I have a data frame which looks like this. How can I create a Time Series from this data frame??
df = pd.read_csv("example.csv", parse_dates=True)
df.tail()
The output is what you see below.
I tried pd.Series(df). However I get this error: ValueError: cannot copy sequence with size 3 to array axis with dimension 729.
Let df
be your dataframe, you can first read it and parse dates with:
df = pd.read_csv('yourfile.csv',parse_dates=['ds'])
then you can set its index to get the time as index with:
df = df.set_index('ds')
and then proceed. It depends on your needs but you should now have a dataframe ready for a time-series analysis.
EDIT:
I tried to reproduce your sample dataframe:
city,ds,bookings
City_1,2013-01-01,55
City_2,2013-01-02,56
And applied the above method it returns:
df = pd.read_csv('yourfile.csv',parse_dates=['ds'])
df = df.set_index('ds')
which returns:
city bookings
ds
2013-01-01 City_1 55
2013-01-02 City_2 56
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.