Data frame rate

I have a data frame indexed with a date (Python datetime object). How to determine the frequency as the number of months of data in a data frame?

I tried the attribute data_frame.index.freq, but it returns none. I also tried using the function asfrequsing data_frame.asfreq('M',how={'start','end'}, but does not return the expected results. Please advise how I can get the expected results.

+4
source share
2 answers

You want to convert the datetimes index to DatetimeIndex, the easiest way is to use to_datetime:

df.index = pd.to_datetime(df.index)

Now you can perform timeseries / frame operations such as resample or TimeGrouper.

, df.index.freq, (, ), df.index.freq None.

+2

, pandas datetime "freq".

import pandas as pd
dates = pd.date_range('2012-1-1','2012-2-1')
df = pd.DataFrame(index=dates)
print (df.index.freq)

,

<Day>

dataframe ,

df.index = [pd.Timestamp(d) for d in df.index]
+2

Source: https://habr.com/ru/post/1536043/


All Articles