第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

熊貓數(shù)據(jù)框中的最大值和最小值

熊貓數(shù)據(jù)框中的最大值和最小值

慕尼黑的夜晚無繁華 2022-07-26 16:15:36
我有一個(gè) pandas 數(shù)據(jù)框,它顯示 1990 年的每小時(shí)溫度讀數(shù),如下所示:           Date and time  Dry bulb temperature0    1990-01-01 00:00:00                   8.21    1990-01-01 01:00:00                   8.12    1990-01-01 02:00:00                   8.33    1990-01-01 03:00:00                   8.54    1990-01-01 04:00:00                   8.8...                  ...                   ...8755 1990-12-31 19:00:00                   3.08756 1990-12-31 20:00:00                   2.68757 1990-12-31 21:00:00                   2.88758 1990-12-31 22:00:00                   4.28759 1990-12-31 23:00:00                   2.0我想每 24 小時(shí)計(jì)算一次最大干球溫度并獲得相應(yīng)的日期和時(shí)間。我該怎么辦?到目前為止,我有:o=[]for i in range(0, len(Dataframe['Dry bulb temperature']), 24):    ymax = np.max(Dataframe['Dry bulb temperature'][i:i+24])    o.append(ymax)print(o)它每 24 小時(shí)給出一次最高溫度,如下所示:[9.7, 9.9, 8.4, 10.4, 11.2, 12.0, 10.5, 10.7, 11.9, 12.0, 11.5, 11.4, 10.2, 10.9, 13.6, 11.5, 9.6, 10.9, 10.8, 12.3, 12.3, 12.2, 11.5, 7.9, 12.7, 6.0, 9.4, 8.2, 9.8, 10.6, 9.6, 8.8, 10.8, 8.6, 11.9, 11.7, 12.2, 13.8, 12.5, 10.8, 13.2, 8.2, 7.4, 12.1, 12.4, 8.6, 7.7, 12.3, 13.3, 12.3, 13.1, 12.0, 12.7, 11.5, 12.7, 12.5, 12.5, 8.7, 13.2, 7.7, 9.0, 10.1, 10.6, 10.9, 11.9, 11.4, 13.3, 12.2, 15.0, 14.1, 13.1, 12.9, 13.7, 12.7, 12.7, 16.3, 14.9, 12.8, 11.8, 14.2, 11.5, 11.7, 10.4, 10.1, 9.9, 9.6, 10.6, 12.7, 16.0, 15.3, 14.4, 14.2, 8.6, 7.0, 9.8, 11.6, 12.6, 11.1, 12.3, 12.2, 14.8, 15.2, 11.3, 12.1, 12.0, 12.3, 11.5, 10.8, 10.0, 11.7, 15.3, 12.9, 17.0, 17.6, 18.9, 14.2, 13.3, 14.9, 17.8, 20.6, 21.9, 24.1, 26.8, 25.4, 24.9, 23.5, 16.4, 14.9, 13.8, 14.2, 17.7, 17.9, 16.8, 15.7, 16.3, 18.9, 19.4, 18.3, 14.5, 17.6, 18.8, 18.1, 21.9, 18.2, 14.7, 14.9, 19.4, 20.0, 14.9, 18.9, 16.8, 17.6, 15.8, 14.6, 17.0, 我想以表格形式獲取每個(gè)最高溫度的相應(yīng)日期:[9.7,1990-01-02 03:00:00],...,etc. 
查看完整描述

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


查看完整回答
反對(duì) 回復(fù) 2022-07-26
?
守著星空守著你

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)


查看完整回答
反對(duì) 回復(fù) 2022-07-26
  • 2 回答
  • 0 關(guān)注
  • 106 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)