Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove freq='W-FRI' portion in Timestamp

okay so I have two data frames both with datetime as indices.

When I call df1 index, I get:

df1.index[0]
Timestamp('2016-03-04 00:00:00')

when I call df2 index, i get:

df2.index[0]
Timestamp('2016-03-11 00:00:00', freq='W-FRI')

I'm trying to remove the freq='W-FRI' part. I want my second data frame (df2) to return the follow when I call for the first index:

df2.index[0]
Timestamp('2016-03-03 00:00:00')

Thanks so much. This small difference is not allowing me to index my data frames with dates.

like image 588
confused_intern Avatar asked Oct 26 '25 19:10

confused_intern


1 Answers

You have a DatetimeIndex with a freq. Set it to None

import pandas as pd

idx = pd.date_range('2010-01-01', freq='W-FRI', periods=10)
idx[0]
#Timestamp('2010-01-01 00:00:00', freq='W-FRI')

idx.freq=None
idx[0]
#Timestamp('2010-01-01 00:00:00')

All DatetimeIndex objects have a frequency attribute, the default is None.

pd.DatetimeIndex(['2010-01-01', '2011-01-02'])
#DatetimeIndex(['2010-01-01', '2011-01-02'], dtype='datetime64[ns]', freq=None)
like image 92
ALollz Avatar answered Oct 29 '25 13:10

ALollz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!