[英]invalid type comparison error
I have been using this code: 我一直在使用此代码:
df = df[df['A']>0]
df.loc[(df['A']<0), 'A'] = df['A'].median()
I am getting error invalid type comparison. 我收到错误无效类型比较。
I would like to replace all values in the column A that are negative with median, mean or drop them. 我想将A列中所有值为负的值替换为中值,均值或丢弃它们。
Any explanation ? 有什么解释吗?
EDIT: (continuation of Calculate column value based on 2 dataframes ) 编辑:( 基于2个数据框继续计算列值 )
df1['A'] = dates.sub(df1['Date1'], axis=0)
print (df1)
Date1 A
L-22 2015-03-12 668
L-15 2016-02-26 -46
There is problem some bad nonumeric value, so need to_numeric
: 有一些不好的非数字值的问题,所以需要
to_numeric
:
df['A'] = pd.to_numeric(df['A'], errors='coerce')
For filtering need boolean indexing
: 对于过滤需要
boolean indexing
:
df = df[df['A'] < 0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.