Read data with a time index
pandas DataFrame objects can have an index denoting time, this recognized by Matplotlib for axis labeling.
This exercise involves reading data from climate_change.csv, containing CO2 levels and temperatures recorded on the 6th of each month from 1958 to 2016, using pandas' read_csv function. The parse_dates and index_col arguments help set a DateTimeIndex.
Don't forget to check out the Matplotlib Cheat Sheet for a quick overview of essential concepts and methods.
This exercise is part of the course
Introduction to Data Visualization with Matplotlib
Exercise instructions
- Import the pandas library as
pd. - Read in the data from a CSV file called
'climate_change.csv'usingpd.read_csv. - Use the
parse_dateskey-word argument to parse the"date"column as dates. - Use the
index_colkey-word argument to set the"date"column as the index.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import pandas as pd
____
# Read the data from file using read_csv
climate_change = pd.read_csv(____, ____, ____)