【发布时间】:2021-06-30 16:38:27
【问题描述】:
我有一个庞大的数据集,我正在尝试将时间戳列解析为以下格式:
YYYY-MM-DD HH:MM:SS:DEC 但我在数据框中的输出类似于:210309_131046520_11。
因此:我想将输出列拆分为以下列:
date, day, month, year, dec, hh, mm, ss
例如:210309_131046520_11
date 21-03-09day 09month 03year 2021dec 520hh 13
@ 987654331@10ss46
我尝试使用datetime 模块,但似乎没有任何帮助。有人可以帮忙吗?
我的时间戳列示例:
0 210309_131046520_11.sgy
1 210309_131046520_05.sgy
2 210309_131046528_02.sgy
3 210309_131046528_12.sgy
4 210309_131049712_07.sgy
...
162 210309_132658584_07.sgy
163 210309_132659632_10.sgy
164 210309_132701232_05.sgy
165 210309_132704256_02.sgy
166 210309_132707136_12.sgy
我的日期列示例:
0 131046520
1 131046520
2 131046528
3 131046528
4 131049712
...
162 132658584
163 132659632
164 132701232
165 132704256
166 132707136
我尝试过的一件事:
使用split:
s_df["date"] = s_df["timestamp"].apply(lambda row: row.split("_")[1])
输出:
TypeError: list indices must be integers or slices, not str
【问题讨论】:
标签: python pandas dataframe parsing timestamp