I have a column of values that are all supposed to be in dollars. The first value is a number and I want to convert it to dollars to match the other values. What is the quickest way to apply formatting to a single row? I am hoping to get $247,000 in row [0].
Asked
Active
Viewed 162 times
-1
-
2Please don't post images. Post everything as text. Also, please post your expected output based on sample input for better clarity. – Mayank Porwal Jan 26 '21 at 05:02
2 Answers
1
This would be the easiest way to add dollar symbol (or any string) in every rows of the column.
dataframe[0] = '$'+dataframe[0].astype(str)

Dharman
- 30,962
- 25
- 85
- 135

Ranjith kumar
- 140
- 7
1
- use
iloc[0]
to find the first element in the column - format
f'{x:,}'
will give a number's thousand separate symbol, e.g.f'{1000:,}'
give'1,000'
obj.iloc[0] = f'${obj.iloc[0]:,}'

Ferris
- 5,325
- 1
- 14
- 23
-
1While the code may be a valid answer, adding some explanation would make it more useful to OP and future readers – mousetail Jan 26 '21 at 09:19