简体   繁体   English

将日期格式为“ mm / dd / yyyy”的Pandas数据框中的所有行值更改为“ yyyy-mm-dd”

[英]Change all row values in Pandas dataframe in date format “mm/dd/yyyy” to “yyyy-mm-dd”

Like the title states, I have two csv files I have read into a Pandas dataframe and I want to join the two tables on their "Dates" column values. 像标题状态一样,我有两个csv文件,我已将其读入Pandas数据框中,并且希望将两个表连接到其“日期”列值上。 I'm having an issue converting the special character "/" to "-" and switching the ordering to year-month-day. 我在将特殊字符“ /”转换为“-”并将顺序切换为年-月-日时遇到问题。 Any easy quick way that will convert all the row values from the "mm/dd/yyyy" format to the correct "yyyy-mm-dd" format for the join? 任何简单快速的方法都可以将所有行值从“ mm / dd / yyyy”格式转换为联接的正确“ yyyy-mm-dd”格式?

When you read your csv adding parse_dates 当您阅读csv时添加parse_dates

pd.read_csv('q.csv',parse_dates=True)

Or 要么

pd.read_csv('q.csv',parse_dates=['Dates'])# your date format column here

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

相关问题 检查日期格式 YYYY-MM-DD - Checking a date format YYYY-MM-DD 将python中索引的日期格式从yyyy-dd-mm更改为yyyy-mm-dd - Change date format for an index in python from yyyy-dd-mm to yyyy-mm-dd Python Dataframe 日期列 - 将格式更改为 yyyy-mm-dd - Python Dataframe column of dates - change format to yyyy-mm-dd 使用 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 在 DD/MM/YYYY 和 YYYY-MM-DD 之间转换日期? - Converting date between DD/MM/YYYY and YYYY-MM-DD? 如何更改日期格式(从 yyyy-MM-DD 到 yyyy-MM) - How to change date format (from yyyy-MM-DD to yyyy-MM) 如何在熊猫中将dd-mm-yyyy日期格式更改为yyyy-dd-mm - how to change dd-mm-yyyy date format to yyyy-dd-mm in pandas Pandas - 检查是否有任何列是日期时间并将其更改为日期格式字符串(yyyy-mm-dd) - Pandas - Check if any column is date time and change it to date format string (yyyy-mm-dd) 如何将不同格式的字符串(YYYY-MM-DD,DD-MM-YYYY)转换为熊猫中一种格式的日期对象? - How to convert string of different format(YYYY-MM-DD, DD-MM-YYYY) to date object of one format in pandas? 将 Pandas 日期列格式从“MMDDYYYY”更改为“YYYY-MM-DD” - Change Pandas date column format from "MMDDYYYY" to "YYYY-MM-DD"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM