简体   繁体   English

Python:如何将 UTC 时间戳从 mm/dd/yyyy hh:mm:ss AM 更改为 dd/mm/yyyy hh:mm:ss AM

[英]Python: How to change a UTC timestamp from mm/dd/yyyy hh:mm:ss AM to dd/mm/yyyy hh:mm:ss AM

I am trying to change the format of a UTC timestamp in a csv file but nothing seems to be working.我正在尝试更改 csv 文件中 UTC 时间戳的格式,但似乎没有任何效果。 It keeps saying that there is a ValueError does not match format '%m/%d/%Y %I:%M:%S %p' Below there is an example of the CSV column一直说有一个 ValueError does not match format '%m/%d/%Y %I:%M:%S %p'下面是 CSV 列的示例

Example of CSV column CSV 列示例

df[' UTC Event Timestamp'] = df[' UTC Event Timestamp'].astype(str)
string_col = str(df)
string_col.strip()

datetime.strptime(string_col, '%m/%d/%Y %I:%M:%S %p')
datetime.strptime(string_col, '%m/%d/%Y %I:%M:%S %p').strftime('%d/%m/%Y %I:%M:%S %p')

print(string_col)
df['UTC Event Timestamp'] = pd.to_datetime(df['UTC Event Timestamp'])
df['UTC Event Timestamp'] = df['UTC Event Timestamp'].apply(lambda x: x.strftime('%d/%m/%Y %I:%M:%S %p'))

You can use您可以使用

df['string_col'].apply(lambda row: datetime.strptime(row, '%m/%d/%Y %I:%M:%S %p').strftime('%d/%m/%Y %I:%M:%S %p'))

to convert the column in to datetime format.将列转换为日期时间格式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python:如何将 UTC 时间戳从 mm/dd/yyyy hh:mm:ss AM 更改为 dd/mm/yyyy hh:mm:ss AM - Python: How can I change a UTC timestamp from mm/dd/yyyy hh:mm:ss AM to dd/mm/yyyy hh:mm:ss AM 使用 python 将日期格式 mm/dd/yyyy hh:mm:ss AM 更改为 yyyy-mm-dd hh:mm:ss 格式 - change date format mm/dd/yyyy hh:mm:ss AM to yyyy-mm-dd hh:mm:ss format using python 如何将 csv 文件中的时间格式从 DD:MM:YY HH:MM 更改为 YYYY-MM-DD HH:MM:SS。 或 YYYY/MM/DD HH:MM:SS - How to change time format in a csv file from DD:MM:YY HH:MM to YYYY-MM-DD HH:MM:SS. or YYYY/MM/DD HH:MM:SS 在 python 中将日期从 DD/MM/YYYY HH.mm.ss 转换为 MM-DD-YYYY HH:MM:SS 时出错 - Error converting date from DD/MM/YYYY HH.mm.ss to MM-DD-YYYY HH:MM:SS in python 将DD / MM / YYYY HH:MM:SS转换为MySQL TIMESTAMP - Convert DD/MM/YYYY HH:MM:SS into MySQL TIMESTAMP 如何使用 Python 将 CSV 文件中的日期和时间格式从 dd-mm-yyyy & hh:mm:ss 更改为 mm/dd/yyyy & hh:mm? - How can I change date and time format in a CSV File from dd-mm-yyyy & hh:mm:ss to mm/dd/yyyy & hh:mm using Python? 将字符串 MM-dd-yyyy hh:mm:ss 转换为 PySpark 中的时间戳 yyyy-MM-dd hh:mm:ss - Convert string MM-dd-yyyy hh:mm:ss to timestamp yyyy-MM-dd hh:mm:ss in PySpark Python 日期时间转换格式为 dd/mm/yyyy HH:MM:SS - Python Datetime convert format into dd/mm/yyyy HH:MM:SS 将字符串“YYYY-MM-DD hh:mm:ss Etc/GMT”转换为 UTC 时间戳 pandas - Convert String "YYYY-MM-DD hh:mm:ss Etc/GMT" to timestamp in UTC pandas 从 YYYY-DD-MM HH:MM:SS 获取 YYYY-DD-MM - Get YYYY-DD-MM from YYYY-DD-MM HH:MM:SS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM