[英]How to remove characters from timestamps in a dataframe in Python
I am trying to remove the brackets and apostrophes from a dataframe in pandas, so that I can further parse the timestamp, which is in this format: YYYY/MM/DD:HH:MM:SS.我试图从 Pandas 的数据框中删除括号和撇号,以便我可以进一步解析时间戳,格式如下:YYYY/MM/DD:HH:MM:SS。
The code I'm using looks like this:我正在使用的代码如下所示:
finallog = newerlog.split()
ts = finallog[0::6]
ip = finallog[1::6]
proxy = finallog[3::6]
refurl = finallog[4::6]
requrl = finallog[5::6]
An example of an erroneous timestamp at the beginning of the dataframe is: ['2020/11/13:02:16:43 There are others in the dataframe that have an apostrophe, such as '2020/11/14:10:14:16 Of course, the final element has the closing inverse as the beginning example ']数据帧开头错误时间戳的示例是: ['2020/11/13:02:16:43 数据帧中还有其他带有撇号的时间戳,例如 '2020/11/14:10:14 :16 当然,最后一个元素有结束逆作为开始例子']
Any advice on how to remove these?有关如何删除这些的任何建议? The timestamps need to be uniform length if I am to slice them further.如果我要进一步切片,时间戳需要统一长度。
if you know all the erroneous characters already:如果您已经知道所有错误字符:
element = '["2020/11/13:02:16:43'
clean_element = element.replace('[', '').replace('"', '').replace("'", '').replace(']', '')
>> '2020/11/13:02:16:43'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.