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.
Any explanation ?
EDIT: (continuation of Calculate column value based on 2 dataframes )
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
:
df['A'] = pd.to_numeric(df['A'], errors='coerce')
For filtering need boolean indexing
:
df = df[df['A'] < 0]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.