将多个DateTime列合并为一列(Python)
我试图把我所有的约会时间信息收集到一个栏目里。现在,我在6个月的时间跨度内为每个时期都有一个列,但是为了进行时间序列分析,我试图将所有日期时间收集到一个列中 以下是我所累的:将多个DateTime列合并为一列(Python),python,pandas,datetime,typeerror,keyerror,Python,Pandas,Datetime,Typeerror,Keyerror,我试图把我所有的约会时间信息收集到一个栏目里。现在,我在6个月的时间跨度内为每个时期都有一个列,但是为了进行时间序列分析,我试图将所有日期时间收集到一个列中 以下是我所累的: df['Dates'] = df["1 Month Date"]+ df["2 Month Date"]+ df["3 Month Date"] + df["4 Month Date"] + df["5 Month Date&quo
df['Dates'] = df["1 Month Date"]+ df["2 Month Date"]+ df["3 Month Date"] + df["4 Month Date"] + df["5 Month Date"] +df["6 Month Date"]
错误消息:
TypeError: cannot add DatetimeArray and DatetimeArray
二审:
Dates = df["1 Month Date","2 Month Date","3 Month Date","4 Month Date","5 Month Date","6 Month Date"]
错误消息:
KeyError: ('1 Month Date', '2 Month Date', '3 Month Date', '4 Month Date', '5 Month Date', '6 Month Date')
额外信息:这是一张excel表格,我使用panda、我的1个月日期、2个月日期等导入。。是执行df.info()时的datetime64[ns]
样本数据:
1 Month Date 1 Month Room Booked 2 Month Date 2 Month Room Booked \
0 2020-09-01 339 2020-10-01 346
1 2020-09-01 2 2020-10-01 4
2 2020-09-01 4 2020-10-01 4
3 2020-09-01 0 2020-10-01 0
4 2020-09-01 0 2020-10-01 0
5 2020-09-01 1 2020-10-01 1
6 2020-09-01 2 2020-10-01 2
7 2020-09-01 50 2020-10-01 58
8 2020-09-01 12 2020-10-01 12
9 2020-09-01 9 2020-10-01 9
10 2020-09-01 6 2020-10-01 6
11 2021-03-01 112 2021-04-01 112
12 2021-03-01 0 2021-04-01 0
13 2021-02-01 36 2021-03-01 36
14 2021-02-01 18 2021-03-01 18
15 2021-02-01 20 2021-03-01 20
16 2021-02-01 12 2021-03-01 12
17 2021-02-01 0 2021-03-01 0
IIUC用途:
Dates = df[["1 Month Date","2 Month Date","3 Month Date","4 Month Date","5 Month Date","6 Month Date"]].apply(pd.Series.explode).sum(axis=1)
什么是打印(df.info())?你也使用最新的熊猫版本吗?嘿,谢谢你的评论,df.info告诉你你有什么类型的数据,所以我的是datetime64[ns],我想是的,它会如何影响我正在尝试做的事情?如何检查?预期输出应为2列?不,共有6列,例如1个月日期、2个月日期到6,我试图将所有这些6个月的日期收集到所有日期的1列中,但当我打印时(df.Dates)上面写着:AttributeError:'DataFrame'对象没有属性'Dates'@Xijy1111-你能创建一个小数据样本来查看数据的外观吗?e、 三行三列。当我打印(日期)时,它会显示(如下)我不能用于我的时间序列分析0.0 1 0.0 2 0.0 3 0.0 4 0.0 5 0.0 6 0.0 7 0.0 8 0.0 9 0.0 10 0.0 11 0.0 12 0.0 13 0.0 14 0.0 15 0.0 16 0.0 17 0.0 18 0.0 19 0.0 20 0.0 21 0.0 22 0.0 23 0.0 24 0.0让我知道你的想法think@XIUJY1111-老实说,如果error
TypeError:无法添加DatetimeArray和DatetimeArray
似乎是一些列表数据,但我需要具有相同错误的小数据样本。可以创建它并添加到问题中吗?嘿,我添加了一些数据示例