python - 如何使用 Pandas 在 python 中更改日期格式

标签 python pandas

我正在处理 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/

相关文章:

python - 我的算法最坏情况下的运行时间是多少

python - Gnuradio(3.7.9) : how to add a qt widget such as slider to the flowgraph?(新版本不支持pyqwt)

python - Google oAuth2 python 应用程序无法在线打开登录页面

python - 使用 Pandas 创建每小时/每分钟时间范围

python - 根据条件在多个数据帧的数据帧内的列之间交换行

python - 将一个时间序列插入到自定义时间序列中

python - 组内累计金额

python - 我可以调整这个seaborn 热图中颜色条的比例吗?

python Pandas : Check if all columns in rows value is NaN

python - 包含一列列表的 Pandas DataFrame 中的行重复 (Python3)