pd.date_range , Length of values does not match lenght of index

Viewed 52

I have a data frame composed as follows, containing daily precipitation data from 1971 to 2017:

df.dtypes
Out[28]: 
date    datetime64[ns]
mm             float64
dtype: object

df.head()
Out[29]: 
                 date   mm
0 1971-01-01 07:00:00  2.2
1 1971-01-02 07:00:00  2.0
2 1971-01-03 07:00:00  3.0
3 1971-01-04 07:00:00  0.0
4 1971-01-05 07:00:00  0.0

I want to ask the user to which time frame he´s interested to filter the available data, therefore:

start_date_entry = input("Input the month and the year to start your analysis  (i.e. YYYY-MM-DD):    ")
    year, month, day = map(int, start_date_entry.split('-'))
    start_date_form = datetime(year, month, day,7,0,0)

end_date_entry = input("Input the last month and year to end your analysis  (i.e. YYYY-MM-DD):    ")
    year, month, day = map(int, end_date_entry.split('-'))
    end_date_form = datetime(year, month, day,7,0,0)

Both start_date_form and end_date_form have the following format:

type(start_date_form)
Out[31]: datetime.datetime

print(start_date_form)
2010-01-01 07:00:00

Now, I want to filtrate my data frame with the new dates:

df['date']=pd.date_range(start=(start_date_form), end=(end_date_form),freq='D')

I get the following error:

Length of values (1827) does not match length of index (17167)

I am new to python and programming, I would appreciate some help on this. Thanks

0 Answers
Related