我這樣做:
pandas.concat([
yfinance.download('btc-usd',interval="1d")["Close"],
yfinance.download('aapl',interval="1d")["Close"]
],axis=1)
這給了我一個帶有 NaN 值的資料框,如下所示:
Close Close
Date
1980-12-12 0.128348 NaN
1980-12-12 0.128348 NaN
1980-12-16 0.112723 NaN
1980-12-17 0.115513 NaN
1980-12-18 0.118862 NaN
... ... ...
2021-12-27 180.330002 50640.417969
2021-12-28 179.289993 47588.855469
2021-12-29 179.380005 46444.710938
2021-12-30 178.199997 47178.125000
2021-12-31 NaN 47804.882812
我需要洗掉所有包含 NaN 值的行。
uj5u.com熱心網友回復:
有很多帖子回答了圍繞該主題的問題,因此這可能是重復的。例如,這篇文章回答了一個非常相似的問題。首先,您需要將concat()程序的結果分配給一個變數,例如 df,然后您只需使用dropna(). 確保將引數設定inplace為False或將函式呼叫的結果重新分配給變數,以便您可以跟蹤您感興趣的行。
df = pandas.concat([
yfinance.download('btc-usd',interval="1d")["Close"],
yfinance.download('aapl',interval="1d")["Close"]
],axis=1)
df.dropna(inplace=True)
df
Close Close
Date
2021-12-27 180.330002 50640.417969
2021-12-28 179.289993 47588.855469
2021-12-29 179.380005 46444.710938
2021-12-30 178.199997 47178.125000
uj5u.com熱心網友回復:
如果您的資料存盤在 中df,df.dropna(axis="index")則將洗掉其中包含任何 NaN 的行。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/399103.html
下一篇:資料框條件洗掉重復行
