我正在处理 Pandas 中的大数据,但日期格式有问题,这是一列的格式
Wed Feb 24 12:06:14 +0000 2021
我认为用这样的格式更改所有列的格式更容易'%d/%m/%Y, %H:%M:%S'
我怎样才能做到这一点?
最佳答案
您可以对数据集使用以下函数。
def change_format(x):
format = dt.datetime.strptime(x, "%a %b %d %H:%M:%S %z %Y")
new_format = format.strftime('%d/%m/%Y, %H:%M:%S')
return new_format
然后使用 df['date_column'] = df['date_column'].apply(change_format)
应用它.这里
df
是你的数据集。
关于python - 如何使用 Pandas 在 python 中更改日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67085072/