我已经使用Pandas导入了一个Excel工作表,如下所示:
w = pd.read_excel(r"C:\Users\lvk\Downloads\Softwares\Prob.xls", header=None)
一旦我导入了Excel工作表,我需要删除任何列中甚至只有一个零的行。 Python中有任何函数可以做到这一点吗? 请让我知道。
输入:
row1: 0 4 3 5
row2: 1 6 5 61
row3: 1 3 6 0
预期输出:
1 6 5 61
答案 0 :(得分:0)
Pandas具有indexing and selecting data的非常强大的界面。其中包括使用loc
关键字按行访问,以及使用方括号将索引逻辑传递给loc
。通常,您可以使用列名对它们的值进行逻辑运算。在这里,我不知道您的excel数据的索引或列,因此我们将遍历其中的所有列。
# We are going to look in each column
for col in w.columns:
# And select only the rows in w that don't have a 0 in that column
w = w.loc[w[column] != 0]