作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在寻找一种使用 Python 编辑 Excel 设备列表的快速方法。
目前我正在查看一个设备列表,其中包含许多在数量列上包含“0”的行项目。
我想删除这些数量为“0”的行。
例子:
from this:
1 | Pots | 3 | 10.99
2 | Pans | 0 | 16.99
3 | Spoons | 1 | 11.99
4 | Forks | 7 | 0.99
5 | Knives | 0 | 20.99
6 | Lids | 0 | 12.99
7 | Spatulas| 2 | 5.99
8 | Tongs | 8 | 6.99
9 | Grill | 1 | 12.99
to this:
1 | Pots | 3 | 10.99
3 | Spoons | 1 | 11.99
4 | Forks | 7 | 0.99
7 | Spatulas| 2 | 5.99
8 | Tongs | 8 | 6.99
9 | Grill | 1 | 12.99
# Here is what I have done so far
import numpy as np
d = {
'Equipment':['Pots','Pans','Spoons','Forks','Knives','Lids',
'Spatulas','Tongs','Grill','Skewers'],
'QTY':[3,0,1,7,0,0,2,8,1,0]}
df = pd.DataFrame(d,columns=['Equipment','QTY'])
df[df.QTY != 0]
最佳答案
你几乎拥有它:
import pandas as pd
df = pd.read_excel("file.xlsx")
df = df[df.QTY != 0]
df.to_excel("file.xlsx", index=False)
关于python - 如果某个单元格包含带有python的 "0",有没有办法在excel中删除一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57861183/
我是一名优秀的程序员,十分优秀!