简体   繁体   English

日期时间列在 mm/dd/yyyy 中,需要 dd/mm/yyyy

[英]DateTime column coming in mm/dd/yyyy, want dd/mm/yyyy

In the long run, I'm trying to be able to merge different dataframes of data coming from different sources.从长远来看,我试图能够合并来自不同来源的不同数据帧。 The dataframes themselves are all a time series.数据框本身都是时间序列。 I'm having difficulty with one dataset.我在处理一个数据集时遇到了困难。 The first column is DateTime.第一列是日期时间。 The initial data has a temporal resolution of 15 s, but in my code I have it being resampled and averaged for each minute (this is to have the same temporal resolution as my other datasets).初始数据的时间分辨率为 15 秒,但在我的代码中,我每分钟对其进行重新采样和平均(这是为了与我的其他数据集具有相同的时间分辨率)。 What I'm trying to do, is make this 0 key of the datetimes, and then concatenate this horizontally to the initial data.我正在尝试做的是将日期时间设为 0 键,然后将其水平连接到初始数据。 I'm doing this because when I set the index column to 'DateTime', it seems to delete that column (when I export as csv and open this in excel, or print the dataframe, this column is no longer there), and concatenating the 0 (or df1_DateTimes, as in the code below) to the dataframe seems to reapply this lost data.我这样做是因为当我将索引列设置为 'DateTime' 时,它似乎删除了该列(当我导出为 csv 并在 excel 中打开它,或打印 Z6A8064B5DF4794550,500553C47C550,500553C47C550,500553C47C5 dataframe 的 0(或 df1_DateTimes,如下面的代码)似乎重新应用了这个丢失的数据。 The 0 key is automatically generated when I run the df1_DateTimes, I think it just makes the column header titled 0.当我运行 df1_DateTimes 时会自动生成 0 键,我认为它只是使列 header 标题为 0。

All of the input datetime data is in the format dd/mm/yyyy HH:MM.所有输入日期时间数据的格式为 dd/mm/yyyy HH:MM。 However, when I make this "df1_DateTimes", the datetimes are mm/dd/yyyy HH:MM.但是,当我制作这个“df1_DateTimes”时,日期时间是 mm/dd/yyyy HH:MM。 And the column length is equal to that of the data before it was resampled.并且列长度等于重新采样之前的数据长度。 I'm wondering if anyone knows of a way to make this "df1_DateTimes" in the format dd/mm/yyyy HH:MM, and to have the length of the column to be the same length of the resampled data?我想知道是否有人知道以 dd/mm/yyyy HH:MM 格式制作此“df1_DateTimes”的方法,并使列的长度与重新采样数据的长度相同? The latter isn't as important because I could just have a bunch of empty data.后者并不那么重要,因为我可能只有一堆空数据。 I've tried things like putting format='%d%m%y %H:%M', but it wasn't seeming to work.我已经尝试过诸如设置 format='%d%m%y %H:%M' 之类的方法,但它似乎不起作用。

Or if anyone knows how to resample the data and not lose the DateTimes?或者如果有人知道如何重新采样数据而不丢失日期时间? And have the DateTimes in 1 min increments as well?并且 DateTimes 也以 1 分钟为增量? Any information on any of this would be greatly appreciated.任何有关这方面的任何信息将不胜感激。 Just as long as the end result is a dataframe with the values resampled to every minute, and the DateTime column intact, with the datatype of the DateTime column to be datetime64 (so I can merge it with my other datasets).只要最终结果是 dataframe 的值每分钟重新采样一次,并且 DateTime 列完好无损,DateTime 列的数据类型为 datetime64 (这样我就可以将它与我的其他数据集合并)。 I have included my code below.我在下面包含了我的代码。

df1 = pd.read_csv('PATH',
                           

parse_dates=True, usecols=[0,7,10,13,28], 
                           infer_datetime_format=True, index_col='DateTime')

# Resample data to take minute averages

df1.dropna(inplace=True) # Drops missing values

df1=(df1.resample('Min').mean())

df1.to_csv('df1', index=False, encoding='utf-8-sig')

df1_DateTimes = pd.to_datetime(df1.index.values)

df1_DateTimes = df1_DateTimes.to_frame()

df1_DateTimes.to_csv('df1_DateTimes', index=False, encoding='utf-8-sig'`

Thanks for reading and hope to hear back.感谢您阅读并希望收到回复。

import datetime
df1__DateTimes = k

k['TITLE OF DATES COLUMN'] = k['TITLES OF DATES COLUMN'].datetime.strftime('%d/%m/%y')

I think using the above snippet solves your issue.我认为使用上面的代码片段可以解决您的问题。 It assigns the date column to the formatted version (dd/mm/yy) of itself.它将日期列分配给自身的格式化版本 (dd/mm/yy)。

More on the Kite docs 更多关于风筝文档

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM