timestamps="[Timestamp('2022-08-13 17:25:00'), Timestamp('2022-08-13 18:02:00'),
Timestamp('2022-08-13 18:46:00')]"
# remove square brackets from string and split on "," to create a list from string
timestamps = timestamps[1 :-1 : ].split(", ")
# remove timestamp substrings
dates_ = [elem.replace("Timestamp('","").replace("')","") for elem in
timestamps]
import datetime
#as datetime
ts_as_datetime = [datetime.datetime.strptime(elem, '%Y-%m-%d %H:%M:%S') for elem in dates_]
#and finally as Timestamp as required:
ts_as_timestamp = [datetime.datetime.timestamp(element) for element in ts_as_datetime]
3条答案
按热度按时间zvokhttg1#
由于您标记了pandas,因此可以使用
pd.Series
构造函数和pd.to_datetime
来处理此问题。试试这个:
#输出:
0dxa2lsx2#
一个没有Pandas的解决方案,使用regex来识别大字符串中的相关字符串,然后datetime.strptime将它们转换为实际的datetime:
brccelvz3#
一种没有Pandas的方法,生成一系列时间戳:
问候你,乔霍娜。