Session Ready
Exercise

From a CSV file

CSV files are a common way to store tabular data, and pandas is the easiest way to read them into Python. And easy is no exaggeration, you only need one function to import a CSV file with pandas, and it automatically converts the file to a DataFrame.

In this exercise, you are going to explore the pandas function read_csv() and its arguments to read in a CSV file, which contains records of wildlife strikes. Before starting, run help(pd.read_csv) in the console to view the arguments for the read_csv() function. There are many, but understanding your options will save you lots of time when importing your data.

Instructions 1/4
undefined XP
  • 1

    Load the wildlife strikes data to the variable strikes from strikes.csv. Print and view the head of strikes.

    • 2

      This time you have a TSV file, i.e., tab-separated values. You'll need to specify the delimiter argument.

    • 3

      Use the appropriate argument to assign the correct header. Be careful; the existing header counts as the first row.

    • 4

      Use the index_col argument to set the index to the first column.