Import a file in chunks
When working with large files, it can be easier to load and process the data in pieces. Let's practice this workflow on the Vermont tax data.
The first 500 rows have been loaded as vt_data_first500. You'll get the next 500 rows. To do this, you'll employ several keyword arguments: nrows and skiprows to get the correct records, header to tell pandas the data does not have column names, and names to supply the missing column names. You'll also want to use the list() function to get column names from vt_data_first500 to reuse.
pandas has been imported as pd.
Cet exercice fait partie du cours
Streamlined Data Ingestion with pandas
Instructions
- Use
nrowsandskiprowsto make a dataframe,vt_data_next500, with the next 500 rows. - Set the
headerargument so thatpandasknows there is no header row. - Name the columns in
vt_data_next500by supplying a list ofvt_data_first500's columns to thenamesargument.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Create dataframe of next 500 rows with labeled columns
vt_data_next500 = pd.read_csv("vt_tax_data_2016.csv",
____,
____,
____,
____)
# View the Vermont dataframes to confirm they're different
print(vt_data_first500.head())
print(vt_data_next500.head())