简体   繁体   English

熊猫数据框中的yyyy-MM-ddT00:00:00到yyyy-MM-dd 00:00:00

[英]yyyy-MM-ddT00:00:00 to yyyy-MM-dd 00:00:00 in Pandas dataframe

I believe that my problem is really straightfoward and there must be a really easy way to solve this issue with pandas that I am still not aware of. 我认为我的问题确实很直截了当,必须有一种非常简单的方法来解决我仍然不知道的熊猫问题。

The problem is that I have one column on a pandas dataframe which all the elements are written on this following format: 问题是我在熊猫数据框上有一列,所有元素都以以下格式编写:

 yyyy-MM-ddT00:00:00

I want to translate each element of the column to the following format: 我想将列的每个元素转换为以下格式:

yyyy-MM-dd 00:00:00

And also, afterwards, is it possible from this column of the dataframe, create two more columns now dividing into date and time. 而且,之后,是否有可能从数据框的此列中创建另外两列,现在将其划分为日期和时间。 What I mean is, to get: 我的意思是,要获得:

yyyy-MM-dd 00:00:00

to two more columns, one containing the date: 到另外两列,其中一列包含日期:

yyyy-MM-dd

And the other containing the time: 另一个包含时间:

00:00:00

Hope that I could synthetize everything properly. 希望我能正确地综合一切。 Thank you in advance. 先感谢您。

How about pd.Series.str.split pd.Series.str.split怎么pd.Series.str.split

# import pandas as pd
# df = pd.DataFrame({'Date': ['2019-08-29T12:00:00']})

#                   Date
# 0  2019-08-29T12:00:00

df.Date.str.split('T', expand=True)

#             0         1
# 0  2019-08-29  12:00:00

To simply get rid of the T between date and time string, you could use pd.Series.str.replace : 要简单地删除日期和时间字符串之间的T ,可以使用pd.Series.str.replace

df.Date.str.replace('T', ' ')

# 0    2019-08-29 12:00:00

暂无
暂无

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

相关问题 如何确保此 PyTrends function 中的数据以 YYYY-MM-DD 格式出现,而不是 YYYY-MM-DD 00:00:00 - How to make sure that the data in this PyTrends function comes out in YYYY-MM-DD format and not YYYY-MM-DD 00:00:00 将 Pandas 中的“9999-12-31 00:00:00”转换为“dd/mm/yyyy” - Convert '9999-12-31 00:00:00' to 'dd/mm/yyyy' in Pandas 如何将日期从 yyyy-mm-dd 00:00:00 重新格式化为 m/d/yyyy 的 python 系列 (pandas.core.series.Series)? - How do I reformat a python series (pandas.core.series.Series) of dates from yyyy-mm-dd 00:00:00 to m/d/yyyy? 将 2020-09-01T00:00:00-05:00 时间戳转换为 dd-mm-yyyy - Convert 2020-09-01T00:00:00-05:00 timestamp to dd-mm-yyyy 将日期格式从 csv. 文件中的 python 从 YYYY-MM-DD HH:MM:SS+00:00 转换为 YYYY-MM-DD - Converting a date format from a csv. file in python from YYYY-MM-DD HH:MM:SS+00:00 to YYYY-MM-DD 有没有办法将 pandas 设置为默认 YYY-MM-DD 而不是 YYY-MM-DD 00:00:00? - Is there a way to set pandas to default YYY-MM-DD instead of YYY-MM-DD 00:00:00? 时间格式为 0:00:00 (h:mm:ss) 的 pandas datetime - pandas datetime with time format as 0:00:00 (h:mm:ss) 熊猫:解析 24:00 而不是 00:00 - Pandas: parsing 24:00 instead of 00:00 将 Pandas 数据帧中的所有 NaT 值更改为 Timedelta 00:00:00 - Change all NaT values in Pandas dataframe to Timedelta 00:00:00 在时间= 00:00:00的熊猫数据框中将日期更改为天+ 1 - Change date to day + 1 in a pandas dataframe where time = 00:00:00
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM