Solution 2.1
Perform the following steps to complete the activity:
- Import the
pandas
library:import pandas as pd
- Read the
US_GDP.csv
file from theDatasets
directory into a DataFrame namedGDP_data
. The data is stored in two columns,date
andGDP
, and the date is read in (by default) as theobject
type. The goal of this activity is to first convert thedate
column into a timestamp and then set this column as the index. Finally, save the updated dataset to a new file:fname = '../Datasets/US_GDP.csv' GDP_data = pd.read_csv(fname)
Note
Please change the path of the dataset file (highlighted) based on where you have downloaded it in your system. You can download the file from The-Pandas-Workshop/US_GDP.csv at master · PacktWorkshops/The-Pandas-Workshop · GitHub.
- Display the head of
GDP_data
so that you can see the format of the data in the file:GDP_data.head()
The output should look as follows: