Reputation: 213
I have the following datasets:
1) Dataset with Month as TimeStamp
df = pd.DataFrame(residuals, columns = ['Passengers'])
Passengers
Month
1949-01-01 -0.082329
1949-02-01 -0.040724
1949-03-01 0.060813
1949-04-01 0.027243
1949-05-01 -0.047359
1949-06-01 0.051545
1949-07-01 0.132902
1949-08-01 0.122322
b) Dataset with Month as Int
dz = pd.DataFrame(estacionalitat, columns = ['Passengers'])
Passengers
Month
1 -0.075844
2 -0.089111
3 0.042705
4 0.002147
5 -0.010528
6 0.109443
7 0.198334
8 0.209830
A set oftransformations have been carried out in both datasets but originally data comes from the following dataset:
data = pd.read_csv('AirPassengers.csv', parse_dates=['Month'], index_col='Month', header=0)
I would like to subtract one dataset as from the other as follows:
df-dz
However, when I try to do the above I get the following message:
Cannot compare type 'Timestamp' with type 'int'
I guess this is because 'Month' is of type int in one dataset while in the other is of type Date. Furthermore, I don´t know how to access 'Month' because it is not understood as a column.
Upvotes: 1
Views: 95
Reputation: 862521
If want convert DatetimeIndex
to months use:
df.index = df.index.month
Then get integers in both, columns names are same, so possible subtract:
df = df-dz
print (df)
Passengers
Month
1 -0.006485
2 0.048387
3 0.018108
4 0.025096
5 -0.036831
6 -0.057898
7 -0.065432
8 -0.087508
Upvotes: 2