Convert currency to float (and parentheses indicate negative amounts) Convert currency to float (and parentheses indicate negative amounts) python python

Convert currency to float (and parentheses indicate negative amounts)


Just add ) to the existing command, and then convert ( to - to make numbers in parentheses negative. Then convert to float.

(df['Currency'].replace( '[\$,)]','', regex=True )               .replace( '[(]','-',   regex=True ).astype(float))   Currency0         11      20002     -3000


this is if you want to make sure its added to the DataFrame especially if you have lots of columns which the average DataFrame has so you can work on it

df['Currency']=(df['Currency'].replace( '[\$,)]','', regex=True ) .replace( '[(]','-', regex=True ).astype(float))