Python 使用pandas重新采样数据帧

Python 使用pandas重新采样数据帧,python,pandas,seaborn,resampling,Python,Pandas,Seaborn,Resampling,我有一个叫做df1的数据帧 import numpy as np import matplotlib.pylab as plt import matplotlib.dates as mdates from matplotlib import style import pandas as pd %pylab inline import seaborn as sns sns.set_style('darkgrid') import io style.use('ggplot') from dateti

我有一个叫做df1的数据帧

import numpy as np
import matplotlib.pylab as plt
import matplotlib.dates as mdates
from matplotlib import style
import pandas as pd
%pylab inline
import seaborn as sns
sns.set_style('darkgrid')
import io
style.use('ggplot')
from datetime import datetime
import time    

df1 = pd.read_csv('C:/Users/Demonstrator/Downloads/Listeequipement.csv',delimiter=';', parse_dates=[0], infer_datetime_format = True)
df1.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 17 entries, 145 to 161
Data columns (total 6 columns):
TIMESTAMP                 17 non-null datetime64[ns]
ACT_TIME_AERATEUR_1_F1    17 non-null float64
ACT_TIME_AERATEUR_1_F3    17 non-null float64
ACT_TIME_AERATEUR_1_F5    17 non-null float64
ACT_TIME_AERATEUR_1_F6    17 non-null float64
ACT_TIME_AERATEUR_1_F7    17 non-null float64
dtypes: datetime64[ns](1), float64(5)
memory usage: 952.0 bytes

# build HeatMap
df1['TIMESTAMP']= pd.to_datetime(df_no_missing['TIMESTAMP'], '%d-%m-%y %H:%M:%S')
df1['date'] = df_no_missing['TIMESTAMP'].dt.date
df1['time'] = df_no_missing['TIMESTAMP'].dt.time
date_debut = pd.to_datetime('2015-08-01 23:10:00')
date_fin = pd.to_datetime('2015-08-02 02:00:00')

df1 = df1[(df1['TIMESTAMP'] >= date_debut) & (df1['TIMESTAMP'] < date_fin)]
sns.heatmap(df1.iloc[:,1:6:],annot=True, linewidths=.5)
ax = sns.heatmap(df1.iloc[:, 1:6:], annot=True, linewidths=.5)
ax.set_yticklabels([i.strftime("%Y-%m-%d %H:%M:%S") for i in df1.TIMESTAMP], rotation=0)
我试着对它进行重采样,使其每30分钟(时间戳)具有
ACT\u TIME\u poratier\u 1\u F1值的平均值;第1幕第3幕;行动时间(1)(5);行动时间曝气器1层6;行动时间曝气器1楼7层。

我试着这样做:

TIMESTAMP;ACT_TIME_AERATEUR_1_F1;ACT_TIME_AERATEUR_1_F3;ACT_TIME_AERATEUR_1_F5;ACT_TIME_AERATEUR_1_F6;ACT_TIME_AERATEUR_1_F7
2015-07-31 23:00:00;90;90;90;90;90
2015-07-31 23:10:00;0;0;0;0;0
2015-07-31 23:20:00;0;0;0;0;0
2015-07-31 23:30:00;0;0;0;0;0
2015-07-31 23:40:00;0;0;0;0;0
df1.index = pd.to_datetime(df1.index)
print(df1.resample('30min').mean())
但我有点奇怪:

            ACT_TIME_AERATEUR_1_F1  ACT_TIME_AERATEUR_1_F3  \
1970-01-01               40.588235               40.588235   

            ACT_TIME_AERATEUR_1_F5  ACT_TIME_AERATEUR_1_F6  \
1970-01-01               40.588235               40.588235   

            ACT_TIME_AERATEUR_1_F7  
1970-01-01               40.588235  
我根本没有这些日期1970-01-01


你知道它是如何导入1970的吗?

它会选择默认的整数索引,因此当你执行这些索引的
pd.to\u datetime
时,你会得到那些奇怪的值。您需要将
时间戳
设置为索引

In [2]: df1 = df1.set_index('TIMESTAMP')

In [3]: df1.resample('30min').mean()
Out[3]: 
                     ACT_TIME_AERATEUR_1_F1  ACT_TIME_AERATEUR_1_F3  \
TIMESTAMP                                                             
2015-07-31 23:00:00                      30                      30   
2015-07-31 23:30:00                       0                       0   

                     ACT_TIME_AERATEUR_1_F5  ACT_TIME_AERATEUR_1_F6  \
TIMESTAMP                                                             
2015-07-31 23:00:00                      30                      30   
2015-07-31 23:30:00                       0                       0   

                     ACT_TIME_AERATEUR_1_F7  
TIMESTAMP                                    
2015-07-31 23:00:00                      30  
2015-07-31 23:30:00                       0  

重新采样之前,但使用
转换为_datetime
之后,
df1.index
看起来像什么?在此之前:sns.heatmap(df1.iloc[:,1:6:],annot=True,linewidths=.5)ax=sns.heatmap(df1.iloc[:,1:6:],annot=True,linewidths=.5)ax.set_yticklebels([I.strftime([I.strftime(“%Y-%m-%d%H:%m:%S]),I in.TIMESTAMP]),rotation=0)要获取热图时间戳,需要数据帧索引-我怀疑您还有其他问题。请使用更新的信息编辑您的问题,尤其是代码,因为代码格式在commentsok中丢失。非常感谢