简体   繁体   中英

How to remove a character from a string and convert the rest into integer or decimal, for all values in a column in pandas?

example: I want to convert all values under the column item price at once so that they do not have the '$' sign.

order_id        item_price
0                $2.39
1                $3.39
2                $3.39
3                $2.39
4               $16.98 

try this

for i in range(0,len(df)):
    df['columnname'][i] = df['columnname'][i].replace('$',' ')
df

or faster way maybe

df.columnname = [x.replace('$',' ') for x in df.columnname]

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM