Skip to content
Advertisement

How to modify pandas column if value doesnt match requirements?

I am having trouble to format evenly my pandas df.

It is filled with dates and prices for Stocks, but the prices are not formatted equally.

From the start of 2021, the values have a comma separating the decimal (cents), but from 1998 to 2020, the prices are not seppareted with comma or dot.

How can I add a comma to the values where the comma doesnt show?

Sample of my df:

JavaScript

Advertisement

Answer

For one particukar column MAX. Same can be applied to required columns. You can use pandas.str.replace

In this case a string xxxxxx, it adds comma before last 2 digits like xxxx,xx

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement