

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
Not enough gems
Cost: 6 gems
1: What Is Pandas?
incomplete
2: Series
incomplete
3: DataFrames
incomplete
4: Derived Columns
incomplete
5: Series vs. DataFrame
incomplete
6: Filtering Data
incomplete
7: The Index in Pandas
incomplete
8: Custom Indexes
incomplete
9: Loading Data
incomplete
10: Inspect Head
incomplete
11: Info & Describe
incomplete
12: Inspecting Workflow
incomplete
13: Data Properties
incomplete
14: Inspecting Columns
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
We've set up a few small example DataFrames in code, but real data usually comes from files, which, as you know, need to be loaded.
For CSV data, Pandas offers the pd.read_csv() function function, which loads a CSV file directly into a DataFrame:
df = pd.read_csv("stream_history.csv")
That's it! One line of code loads your entire dataset into a convenient form in memory.
Pandas is also smart enough to use the first row of the CSV as column headers, so you don't have to worry about that (as long as the file is well-formed).
Sometimes reading a massive file into memory isn't what you want. Maybe you're on a machine with limited RAM, and you're trying to work with a 25GB CSV file. The chunksize parameter lets you read the file in smaller DataFrame chunks:
# will read 100 lines into a DataFrame at a time
chunk_size_num_lines = 100
for chunk in pd.read_csv("large_file.csv", chunksize=chunk_size_num_lines):
# do stuff with each dataframe...
process_chunk(chunk)
SnackStack's kitchen sensors export daily readings to CSV files. We need to get them imported as Pandas DataFrames for analysis.
Complete the load_device_data function. It accepts a CSV file path and returns a DataFrame with the file's contents.