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.
data_frame.index.freq
asfreq
data_frame.asfreq('M',how={'start','end'}
You want to convert the datetimes index to DatetimeIndex, the easiest way is to use to_datetime:
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.
df.index.freq
, 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]
Source: https://habr.com/ru/post/1536043/More articles:Unable to get actionbar icon for animation - androidhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1536039/passing-parameters-to-less-file-in-command-line&usg=ALkJrhisBDtIo98RfpbzOKCyo3ESJ4WyXQwhen adding geom_text to ggplot2 when building ggmap - rhow to write a concatenated backtracking parser in haskell - haskellhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1536042/how-can-i-write-one-writes-to-many-classes-in-play-framework-using-inheritance&usg=ALkJrhimzgmKgBHfHgsyUoNdM4FHyquXGghttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1536044/in-dart-is-there-a-way-to-intercept-accesses-and-mutations-to-programming-constructs&usg=ALkJrhi4aOSGq2LKnW6sg_IO5ZN17dXNiQВнутреннее объединение 3 таблиц, дающих повторяющиеся результаты - joinsetTimeout shows the time remaining before reloading the div - AJAX - javascripthttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1536047/jenkins-tomcat-deploymet-error&usg=ALkJrhgVtuyW0ushC9vAnpCbSLDa9lghOARemoving multiple table cells from a specific row - javascriptAll Articles