Amount column consists of texts
I have a column which is supposed to be an integer which is saved as object in the DataFrame. I tried to remove the columns which are not numeric by using the below codes:
df[df.columns[8]] = df[df.columns[8]].apply(pd.to_numeric, errors='coerce').fillna(0).astype(float).astype(int).dropna()
But the code is not working. I tried to replace the texts with 0 but its not working.
This will render string rows to NAs.
df["Amount in USD"] = pd.to_numeric(df["Amount in USD"], errors='coerce')
Then just filter out rows which has NAs.
df = df[df["Amount in USD"].notnull()]
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.