2
我試圖從我的數據框中刪除一行,其中一列的值爲空。我能找到的大部分幫助都涉及去除迄今爲止對我無效的NaN值。從熊貓數據框中刪除具有空值的行
這裏,我已經創建的數據幀:
[在這裏輸入的形象描述] [1]
# successfully crated data frame
df1 = ut.get_data(symbols, dates) # column heads are 'SPY', 'BBD'
# can't get rid of row containing null val in column BBD
# tried each of these with the others commented out but always had an
# error or sometimes I was able to get a new column of boolean values
# but i just want to drop the row
df1 = pd.notnull(df1['BBD']) # drops rows with null val, not working
df1 = df1.drop(2010-05-04, axis=0)
df1 = df1[df1.'BBD' != null]
df1 = df1.dropna(subset=['BBD'])
df1 = pd.notnull(df1.BBD)
# I know the date to drop but still wasn't able to drop the row
df1.drop([2015-10-30])
df1.drop(['2015-10-30'])
df1.drop([2015-10-30], axis=0)
df1.drop(['2015-10-30'], axis=0)
with pd.option_context('display.max_row', None):
print(df1)
這裏是我的輸出:
能人請告訴我如何放棄這一行。最好通過用空值標識行以及如何按日期刪除。我一直沒有和熊貓一起工作過很長時間,我一直堅持這一個小時。任何意見將不勝感激。
這在我的情況下不起作用 –
我的解決方法是在參數 中包含'null' na_values(['NaN','null'])被傳遞給pandas.read_csv()來創建df。仍然沒有解決方案,這是不可能的 –
查看更新的答案與工作示例。 –