Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Streamlined Data Ingestion with pandas

Cursus bekijken

Oefeninstructies

  • Use nrows and skiprows to make a dataframe, vt_data_next500, with the next 500 rows.
  • Set the header argument so that pandas knows there is no header row.
  • Name the columns in vt_data_next500 by supplying a list of vt_data_first500's columns to the names argument.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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())
Code bewerken en uitvoeren