[英]conditionally dropping rows from a pandas dataframe
我正在嘗試有條件地刪除 pandas dataframe 中的行並遇到麻煩。 例如,我想刪除下例中 dataframe 的第二行和第三行。
import pandas as pd
df = pd.DataFrame([
[12, 10, 7, 0],
[11, 0, 0, 3],
[0, 0, 0, 0],
[0, 6, 7, 5],
[4, 11, 3,4],
[5, 2, 5, 0]],
columns=["num1", "num2","num3","num3"])
我試過了:
df.loc[~(df['num2','num3']==0).all(axis=1)]
但出現錯誤“TypeError: only integer scalar arrays can be converted to a scalar index”
嘗試
df.loc[(df['num2']!=0) & (df['num2']!=0)]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.