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

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

按行計(jì)算數(shù)據(jù)框,但按日期時(shí)間分組

按行計(jì)算數(shù)據(jù)框,但按日期時(shí)間分組

嗶嗶one 2022-06-28 18:10:52
我每天使用多條盤(pán)中線來(lái)處理時(shí)間序列數(shù)據(jù)。我希望能夠根據(jù)僅按天分組的數(shù)據(jù)做出決策,而不是作為.groupby()目前我正在做一個(gè)循環(huán),比如np.unique(df.index.date)每天應(yīng)用計(jì)算,但這在大型數(shù)據(jù)集上非常耗時(shí)。for day in np.unique(df.index.date):    if df[day.strftime("%Y-%m-%d")].count()[0] != 5:        df.drop(df[df.index.date == day].index, inplace=True)一段數(shù)據(jù)可能如下所示:Date_Time   EB2018-09-13 9:20:00  69.452018-09-13 9:30:00  69.442018-09-13 9:40:00  69.332018-09-13 9:50:00  69.342018-09-13 10:00:00 69.362018-09-14 9:20:00  69.452018-09-14 9:30:00  69.442018-09-14 9:40:00  69.332018-09-14 9:50:00  69.342018-09-14 10:00:00 69.36該代碼正在遍歷每個(gè)日期時(shí)間并刪除任何沒(méi)有 5 行的日期。
查看完整描述

1 回答

?
茅侃侃

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超22個(gè)贊

我認(rèn)為您應(yīng)該能夠在不循環(huán) Python 的情況下做到這一點(diǎn),并通過(guò)矢量化命令來(lái)利用 C 級(jí)速度。制作一系列日期,進(jìn)行值計(jì)數(shù),使用值計(jì)數(shù)標(biāo)記要保留的數(shù)據(jù),并過(guò)濾掉不需要的數(shù)據(jù)。


# Make a series to use as a mapping for dates which should be kept

dates_with_more_than_5 = df["Date_Time"].dt.date.value_counts() > 4

# Make a column in the DataFrame which indicates which data to keep

df["keeper_data"] = df["Date_Time"].dt.date.map(dates_with_more_than_5).fillna(False)

# Filter the data and drop the keeper "flag" column

df = df[df["keeper_data"].drop(columns="keeper_data"]

你可以用更少的行來(lái)做到這一點(diǎn),但這很容易閱讀。


編輯:另外,我不明白為什么這不能用groupby


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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