2 回答

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超6個(gè)贊
你可以使用這個(gè):
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'})
它為您的問題中的可見數(shù)據(jù)提供了以下輸出:
max min
Date and time
1990-01-01 8.8 8.1
1990-12-31 4.2 2.0
如果您真的希望將結(jié)果作為列表,您可以在之后使用它:
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)]
要獲得每天最大值的確切日期時(shí)間,您可以嘗試以下操作:
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貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超8個(gè)贊
你可以嘗試使用這個(gè):
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)
添加回答
舉報(bào)