Skip to content
Edition NigeriaGlobal
Country

You are in the Nigeria edition. Type your country to switch.

Set up your profile

Financial Data Lab · Lesson 1 of 8

Lab 1: reading CSV files in Python and SQL

A CSV file is the plain-text table most financial data arrives in. This lab shows how to load one into Python with pandas and into a SQLite database, check that it loaded correctly, and catch the usual problems: dates read as text, thousands separators, missing values and duplicated rows.

Advanced10 min read5 steps

This lesson is complete in writing. A video for it is on its way.

What you will learn

  • By the end you can load a CSV file of prices into Python with pandas and into a SQLite database.
  • You can check a loaded table: count its rows, list its columns and their data types, and look at its first and last rows.
  • You can find and fix the common silent errors: dates read as text, thousands separators, blank cells and duplicate rows.
  • You can verify a loaded figure, such as an average close, against a hand calculation.

Key terms in this lesson

CSV file
Comma-separated values: a plain-text file in which each line is a row and commas separate the columns. The most common format for exchanging tables of data.
DataFrame
A table of data in Python's pandas library, with named columns that can each hold a different type, such as dates, text or numbers.

Step 1 of 5

Before you start: tools, data and the rules of the lab

Opening this step…

Step 2 of 5

The sample file

This step opens when you finish the one above.

Step 3 of 5

Loading the file in Python

This step opens when you finish the one above.

Step 4 of 5

Loading the same file into SQLite

This step opens when you finish the one above.

Step 5 of 5

The usual traps and how to catch them

This step opens when you finish the one above.

Key takeaways

The key takeaways open when you finish every step.

Lesson quiz

6 questions. You need 85% to pass.

The quiz opens when you finish every step.

Read first

Stockertim Learn is education. It explains how investing works and never recommends buying or selling anything.

Up next

Financial data & analyticsLab 2: computing returns in codeRead nowLab 2: computing returns in codeFinancial data & analytics · Advanced · 15 minFinancial data & analyticsLab 3: plotting prices and returnsRead nowLab 3: plotting prices and returnsFinancial data & analytics · Advanced · 15 minFinancial data & analyticsLab 4: SQL on a price tableRead nowLab 4: SQL on a price tableFinancial data & analytics · Advanced · 15 minFinancial data & analyticsLab 5: cleaning corporate action…Read nowLab 5: cleaning corporate actions in codeFinancial data & analytics · Advanced · 15 minAI at workFact-checking AI-assisted contentRead nowFact-checking AI-assisted contentAI at work · Intermediate · 15 minTrading: risk, costs and processTrading is not investingRead nowTrading is not investingTrading: risk, costs and process · Intermediate · 15 minBonds & fixed incomeCovenants: the promises inside a…Read nowCovenants: the promises inside a bondBonds & fixed income · Advanced · 15 minAI at workVerifying AI outputsRead nowVerifying AI outputsAI at work · Beginner · 15 minMarket operationsQuoting and pricing: mid, skew a…Read nowQuoting and pricing: mid, skew and riskMarket operations · Advanced · 15 minBonds & fixed incomePreference shares and hybrids: b…Read nowPreference shares and hybrids: between a bond and a shareBonds & fixed income · Advanced · 15 minTrading: risk, costs and processOvertradingRead nowOvertradingTrading: risk, costs and process · Advanced · 15 minFinancial data & analyticsFinancial data sourcesRead nowFinancial data sourcesFinancial data & analytics · Intermediate · 15 min
English