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

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

刪除不同時(shí)間分辨率的天數(shù)列表(分鐘數(shù)據(jù))

刪除不同時(shí)間分辨率的天數(shù)列表(分鐘數(shù)據(jù))

倚天杖 2023-04-25 16:29:30
我有一個(gè)這樣的數(shù)據(jù)框(時(shí)間戳只包含從 9:00 到 20:00)0   2020-05-18 10:18:001   2020-05-18 10:19:002   2020-05-18 10:20:003   2020-05-18 10:21:004   2020-05-18 10:22:00...?   2020-07-20 12:00:00Name: Time, dtype: datetime64[ns]我有幾天的清單(在“incomplete_days”中)我想在 df 中排除0    2020-05-181    2020-05-193    2020-05-214    2020-05-225    2020-05-236    2020-05-24Name: Time, dtype: datetime64[ns]我簡(jiǎn)單地嘗試過(guò),df[df['Time'] != incomplete_days]但是,錯(cuò)誤說(shuō)ValueError: Can only compare identically-labeled Series objects我應(yīng)該用天數(shù)列表制作一個(gè)時(shí)間戳(1 分鐘分辨率)以在 df 中排除它們嗎?如果是這樣,我怎樣才能在給定的日子里安排開(kāi)始時(shí)間和結(jié)束時(shí)間?有什么辦法可以讓我不需要用 1 分鐘的分辨率制作時(shí)間戳嗎?(我已經(jīng)從 20:01 到 08:59 刪除了不相關(guān)的時(shí)間,并在 df 中保留了從 09:00 到 20:00 的時(shí)間。我不想再次使用要排除的天數(shù)列表制作每小時(shí)時(shí)間戳。我使用了以下變量來(lái)減少不相關(guān)的時(shí)間)start = time(6)end = time(20)-----編輯我做了df['Time'].dt.date給0         2020-05-181         2020-05-182         2020-05-183         2020-05-184         2020-05-18             ...    110077    2020-08-02110078    2020-08-02110079    2020-08-02110080    2020-08-02110081    2020-08-02Name: Time, Length: 69042, dtype: object和list_incomplete=incomplete_days.tolist()list_incomplete給[Timestamp('2020-05-18 00:00:00'), Timestamp('2020-05-19 00:00:00'), Timestamp('2020-05-21 00:00:00'), Timestamp('2020-05-22 00:00:00'), Timestamp('2020-05-23 00:00:00'), Timestamp('2020-05-24 00:00:00'), Timestamp('2020-05-25 00:00:00'), Timestamp('2020-05-26 00:00:00'), Timestamp('2020-05-27 00:00:00'), Timestamp('2020-05-28 00:00:00'), Timestamp('2020-05-29 00:00:00'), Timestamp('2020-05-30 00:00:00'), Timestamp('2020-05-31 00:00:00'), Timestamp('2020-06-01 00:00:00'), Timestamp('2020-06-02 00:00:00'), Timestamp('2020-06-03 00:00:00'), Timestamp('2020-06-10 00:00:00'), Timestamp('2020-07-02 00:00:00'), Timestamp('2020-07-05 00:00:00'), Timestamp('2020-07-06 00:00:00')]當(dāng)我做df.drop([df['Time'].dt.date not in incomplete_days],inplace=True)我收到以下錯(cuò)誤。TypeError: 'Series' objects are mutable, thus they cannot be hashed我看到它非常接近但出了點(diǎn)問(wèn)題..
查看完整描述

1 回答

?
牛魔王的故事

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

假設(shè)您有兩個(gè)數(shù)據(jù)框df,并且df1它們的列采用日期時(shí)間格式:


df


    Date

0   2020-05-18 10:18:00

1   2020-05-18 10:19:00

2   2020-05-18 10:20:00

3   2020-05-18 10:21:00

4   2020-05-18 10:22:00

5   2020-07-20 12:00:00

df1


    incomplete_days

0   2020-05-18

1   2020-05-19

3   2020-05-21

4   2020-05-22

5   2020-05-23

6   2020-05-24

您可以使用布爾索引并將兩列轉(zhuǎn)換為具有相同格式的字符串以進(jìn)行比較。使用~with isin(實(shí)際上是“不在”)而不是!=. 您不能用于!=將行與整個(gè)系列進(jìn)行比較,因此您當(dāng)前的方法是語(yǔ)法錯(cuò)誤。在布爾索引中轉(zhuǎn)換格式[]將保持?jǐn)?shù)據(jù)框的初始格式,并且不會(huì)從日期更改為字符串。


df = df[~(df['Date'].dt.strftime('%Y-%m-%d').isin(df1['incomplete_days'].dt.strftime('%Y-%m-%d')))]


Out[38]: 

Date

5 2020-07-20 12:00:00


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

添加回答

舉報(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)