简体   繁体   English

为什么我不能删除 python 中的行?

[英]Why I can't delete the rows in python?

I am trying to delete the rows with missing values in python and the code runs but with no effect whatsoever.我正在尝试删除 python 中缺少值的行,并且代码运行但没有任何效果。 The rows are not deleted.行不会被删除。 I've added also a screenshot of my xls file.我还添加了我的 xls 文件的屏幕截图。

This is how my code looks like:这就是我的代码的样子:

  df = Pandas.read_excel('C:/Downloads/Report.xls')
  engine='python'
  new_df = df.dropna(inplace = true)
  puts new_df.to_string()

I've tried also with: new_df = df.dropna(axis=0, how="any", inplace=false) OR new_df = df.dropna()我也尝试过: new_df = df.dropna(axis=0, how="any", inplace=false) OR new_df = df.dropna()

IT DOES NOT DELETE THE ROWS.它不会删除行。

I get the following result: Unnamed: 2 0 asset_number 1 WG0000000000 2 WG0000204381 3 WG0000204381 4 WG0000204381 5 WG0000204379 6 WG0000204379 7 WG0000204379 8 WG0000204366 9 WG0000204366 10 WG0000204366 11 WG0000204368... I get the following result: Unnamed: 2 0 asset_number 1 WG0000000000 2 WG0000204381 3 WG0000204381 4 WG0000204381 5 WG0000204379 6 WG0000204379 7 WG0000204379 8 WG0000204366 9 WG0000204366 10 WG0000204366 11 WG0000204368... 报告.xls

First fill the empty rows with NaN and then delete the na value as following:首先用 NaN 填充空行,然后删除 na 值,如下所示:

nan_value = float("NaN")
Convert NaN values to empty string
df.replace("", nan_value, inplace=True)
df.dropna(inplace=True)
print(df)

Before dropping:-掉落前:-

在此处输入图像描述

After dropping:-掉落后:-

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法使用 python 删除列表中的重复行 - I can't delete duplicated rows in a list with python 为什么我不能使用此代码删除多条推文? Python tweepy - Why can't I delete multiple tweets with this code? Python tweepy 我找不到使用 Python 删除 csv 文件中包含字符串的行的方法 - I can't find a way to delete rows with strings in my csv file with Python 为什么我不能在Python中从(BeautifulSoup HTML)的此列表中删除重复项? - Why can't I delete duplicates from this list (of BeautifulSoup HTML) in Python? 关于python3列表删除的问题。为什么不能删除带有奇数的偶数? - Question about python3 list deletion。Why can't I delete an even number with an odd number? 为什么我不能从 Python 导入的 CSV 中删除列/字段? - Why can't I delete column/ field from imported CSV in Python? Python Pandas 数据框:不能有条件地删除行,总是在发生事故时删除整个数据集 - Python Pandas Dataframes: Can't Conditionally Delete Rows, Always Delete Entire Dataset on Accident 为什么我不能从列表中删除所需的元素 - Why can't I delete the needed element from the list 为什么不能删除在ProgramData中创建的目录? - Why can't I delete a directory created in ProgramData? 为什么不能从sqlite3上的数据库中删除? - WHy can't i delete from my database on sqlite3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM