时间戳减法必须具有相同的时区

 收藏

我不断收到以下错误:

  • TypeError:时间戳减法必须具有相同的时区或没有
  • 时区

在这条线

df['days_in_Month'].loc[df['Month'] == min_date_Month] = (df['Month_end'] - \
                                                          pd.to_datetime(min_date,format="%Y-%m-%d"))

我的df ['TransactionDate']是具有以下格式的列2019-08-23T00:00:00.000Z。我在Python3.3.7上编程。

df['Month'] = df['TransactionDate'].apply(lambda x : str(x)[:7])
df['Month_begin'] = pd.to_datetime(df['Month'], format="%Y-%m") + MonthBegin(0)
df['Month_end'] = pd.to_datetime(df['Month'], format="%Y-%m") + MonthEnd(1)

df['days_in_Month'] = (df['Month_end'] - df['Month_begin'])#.days()
print(df.columns)
print(df)

min_date = df['TransactionDate'].min()
min_date_Month = min_date[:7]

df['days_in_Month'].loc[df['Month'] == min_date_Month] = (df['Month_end'] - \
                                                          pd.to_datetime(min_date,format="%Y-%m-%d"))
df['Month_begin'].loc[df['Month'] == min_date_Month] = pd.to_datetime(min_date,format="%Y-%m-%d")
回复