gpt4 book ai didi

python - Linux 和 Windows 中的输出不同?

转载 作者:太空宇宙 更新时间:2023-11-03 16:00:01 24 4
gpt4 key购买 nike

    import pandas as pd
df = pd.read_csv('mydataset.csv', parse_dates=['Timestamp'] )
#print (df)

mask=(df['Timestamp'].dt.minute<10) & (df['Timestamp'].dt.hour==0)

df1 = df[mask]
print (df1)

df1= df1.set_index('Timestamp')
#print df1

df1= df1.resample('D').mean()
print (df1)

这是我查找平均值的代码。

Windows 的输出:-

 Timestamp  Temperature1  Temperature2
2016-09-01 53.80 45.80
2016-09-02 32.00 56.60
2016-09-03 30.80 58.30
2016-09-04 31.00 55.60
2016-09-05 31.10 55.60
2016-09-06 31.20 55.50
2016-09-07 30.80 54.90
2016-09-08 30.80 54.60
2016-09-09 31.40 55.10
2016-09-10 30.70 54.80
2016-09-11 31.00 54.60
2016-09-12 31.70 54.90
2016-09-13 31.10 54.70
2016-09-14 NaN NaN
2016-09-15 NaN NaN
2016-09-16 30.30 54.90
2016-09-17 NaN NaN
2016-09-18 31.00 64.60
2016-09-19 NaN NaN
2016-09-20 30.50 56.65
2016-09-21 30.10 56.40
2016-09-22 30.00 55.60
2016-09-23 30.30 56.30
2016-09-24 49.25 44.00
2016-09-25 51.50 47.10
2016-09-26 50.10 45.35
2016-09-27 50.25 48.00
2016-09-28 49.70 45.90
2016-09-29 51.05 48.15
2016-09-30 50.50 48.50

这实际上是我想要的输出,但这里也有一些日期给出了 NaN 值,不明白为什么会发生这种情况,因为我的数据是正确的并且它给出了 NaN。

在 Linux 机器中,输出类似于

Temperature1       35.779053  
temperature2 53.593647

给出组合平均值,而不是按日期单独给出。

我想要按日期计算的 AVG。请在这件事上给予我帮助。我在用 :- python :2.7.12
Pandas :0.17.1

最佳答案

对于Pandas 0.17.1你可以这样做:

df1.resample('D', how='mean')

PS the Resample API has been changed in Pandas 0.18.0 ...

关于 NaN - 您可以检查每天有多少条目:

df1.groupby(pd.TimeGrouper(freq='1D')).size()

关于python - Linux 和 Windows 中的输出不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40420123/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com