简体   繁体   中英

Pandas. Trying to delete rows on condition but code replaces column with another column

So in the beginning I get a look over my db.

print(sales.head)
print(sales['SALE PRICE'].describe())

After that I use a trick to keep rows that don't contain this kind of NULL value

sales['SALE PRICE'] = sales[sales['SALE PRICE'] != ' -  ']

After that I check if everything is done wright

print(sales.head)
print(sales['SALE PRICE'].describe())

But my program just replaces SALE PRICE column with 0th column that contains indexes Any ideas?

You just need to assign result back to sales instead of column.

sales = sales[sales['SALE PRICE'] != ' -  ']
  • sales['SALE PRICE'] != ' - ' This will return Indexes with True and False Values.
  • So sales[sales['SALE PRICE'] != ' - '] This already returns a DataFrame you wants.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM