Convert values to currency with millions and thousands
Question:
I have a dataframe with a column of values in the millions AND thousands:
pd.DataFrame({"Market Value":[25500000, 500000, 1200000, 250000]})
I need to convert the numbers into currency (€) in millions AND thousands. i.e. €25.5M, €500k, €1.2M, €250k
This previous post I have gotten the code to do this conversion but only for columns with values in the millions, not for columns with values in the millions and thousands:
df['Market Value (€)'] = '€' + (df['Market value'].astype(float)/1000000).round(2).astype(str) + 'M'
Is there a way to adjust this code to also convert values in the hundreds of thousands (i.e. 250000 to €250k)?
Answers:
I have a dataframe with a column of values in the millions AND thousands:
pd.DataFrame({"Market Value":[25500000, 500000, 1200000, 250000]})
I need to convert the numbers into currency (€) in millions AND thousands. i.e. €25.5M, €500k, €1.2M, €250k
This previous post I have gotten the code to do this conversion but only for columns with values in the millions, not for columns with values in the millions and thousands:
df['Market Value (€)'] = '€' + (df['Market value'].astype(float)/1000000).round(2).astype(str) + 'M'
Is there a way to adjust this code to also convert values in the hundreds of thousands (i.e. 250000 to €250k)?