2 回答
TA贡献1829条经验 获得超6个赞
你可以使用这个:
df['Date and time'] = pd.to_datetime(df['Date and time'])
df1 = df.set_index('Date and time').resample('D')['Dry bulb temperature'].agg({'max':'max', 'min':'min'})
它为您的问题中的可见数据提供了以下输出:
max min
Date and time
1990-01-01 8.8 8.1
1990-12-31 4.2 2.0
如果您真的希望将结果作为列表,您可以在之后使用它:
df1.reset_index().to_numpy()
[array([Timestamp('1990-01-01 00:00:00'), 8.8, 8.1], dtype=object),
array([Timestamp('1990-12-31 00:00:00'), 4.2, 2.0], dtype=object)]
要获得每天最大值的确切日期时间,您可以尝试以下操作:
df2 = df.set_index('Date and time')
df2.loc[df2.groupby(df2.index.dayofyear).idxmax().iloc[:, 0]]
Dry_bulb_temperature
Date_and_time
1990-01-01 04:00:00 8.8
1990-12-31 22:00:00 4.2
TA贡献1799条经验 获得超8个赞
你可以尝试使用这个:
from datetime import timedelta
day = min(df['Date and time'])
max_day = max(df['Date and time'])
results = list()
while day <= max_day:
# small part of dataframe
temp = df[(df['Date and time'] >= day) & (df['Date and time'] < day + timedelta(1))]
# Row with max temprature
row = df.iloc[temp['Dry bulb temperature'].idxmax()]
results.append([row['Dry bulb temperature'], row['Date and time']])
day += timedelta(1)
添加回答
举报