【发布时间】:2017-06-14 15:19:07
【问题描述】:
我正在尝试从我的数据框中删除一行,其中一列的值为 null。我能找到的大部分帮助都与删除到目前为止对我不起作用的 NaN 值有关。
我在这里创建了数据框:
# 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)
这是我的输出:
有人可以告诉我如何删除这一行,最好是通过空值标识该行以及如何按日期删除?
我与 pandas 合作的时间不长,我已经坚持了一个小时。任何建议将不胜感激。
【问题讨论】:
标签: python pandas dataframe null