Python 3.x 在dataframe列中显示具有假值的行

Python 3.x 在dataframe列中显示具有假值的行,python-3.x,pandas,Python 3.x,Pandas,我正在验证数据框中的“价格”列。样本: ArticleId SiteId ZoneId Date Quantity Price CostPrice 53 194516 9 2 2018-11-26 11.0 40.64 27.73 164 200838 9 2 2018-11-13 5.0 99.75 87.24 373 200838 9 2

我正在验证数据框中的“价格”列。样本:

    ArticleId   SiteId  ZoneId  Date       Quantity Price   CostPrice
53  194516      9          2    2018-11-26  11.0    40.64   27.73
164 200838      9          2    2018-11-13  5.0     99.75   87.24
373 200838      9          2    2018-11-27  1.0     99.75   87.34
我想用假值显示这些行,这样我就知道它们有什么问题了。我该怎么做

True     17984
False       13
Name: Price, dtype: int64

谢谢。

当price
为null()时,您可以打印行。

  • pd.to_numeric(df['Price'],errors='concurve')。isna()
    返回一个
    布尔值,可用于选择导致错误的行。
    
    • 这包括
      NaN
      或带有
      字符串的行
将熊猫作为pd导入
#测试数据
df=pd.DataFrame({'Price':['40.64','99.75','99.75','pd.NA','test','99.0','98.0']})
价格
0  40.64
1  99.75
2  99.75
3.
4试验
5  99. 0
6   98 0
#查找导致问题的行的值
问题_rows=df[pd.to_numeric(df['Price'],errors='concurve').isna()]
#显示(问题行)
价格
3.
4试验
5  99. 0
6   98 0
可供替代的
  • 创建一个额外的列,然后使用它来选择有问题的行
df['Price\u Updated']=pd.to\u numeric(df['Price'],errors='concurve')
价格更新
0  40.64          40.64
1  99.75          99.75
2  99.75          99.75
3南
4测试NaN
5  99. 0南
6980南
#找到问题行
问题行=df.Price[df.Price\u Updated.isna()]
解释
  • 使用
    .to_numeric()
    更新列,然后检查
    NaNs
    不会告诉您为什么必须强制这些行
#更新价格行
df.Price=pd.to_numeric(df['Price'],errors='concurve')
#查一下NaN
问题行=df.Price[df.Price.isnull()]
#显示(问题行)
3南
4楠
5南
6南
名称:Price,数据类型:float64
True     17984
False       13
Name: Price, dtype: int64
print(df_sales[df_sales['Price'].isnull()])

   ArticleId  SiteId  ZoneId       Date  Quantity  Price  CostPrice
1     200838       9       2 2018-11-13         5    NaN     87.240