简体   繁体   English

如何从 Python 数据框中的时间戳中删除字符

[英]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.

相关问题 如何从Python数据框列名称中删除逗号或任何字符 - How to remove comma or any characters from Python dataframe column name 如何从 Python 中的 DataFrame 列中删除选定的特殊字符 - How to remove selected special characters from DataFrame column in Python 如何从大型数据框中删除特定日期时间戳 - How to remove specific day timestamps from a big dataframe 如何从数据框中删除多个字符 - how to remove multiple characters from dataframe 如何从 pandas (python) dataframe 的每一行/列中删除最后几个字符? - How to remove last few characters from each row/column from pandas (python) dataframe? 如何从数据框中删除非字符? python美丽汤 - How can I remove non characters from a dataframe? python beautiful soup 如何从 Python Pandas 的 DataFrame 中的列中删除所有特殊字符和字母? - How to remove all special characters and letters from column in DataFrame in Python Pandas? 如何从Python中的数据框列中的字符串中删除非字母数字字符? - How to remove non-alpha-numeric characters from strings within a dataframe column in Python? 从数据框中的字符串中删除字符 - Remove characters from a string in a dataframe 如何在 Python Regex Dataframe 中删除多个特殊字符模式 - How to remove multiple patterns of special characters in Python Regex Dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM