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
添加回答
舉報(bào)