Pandas Series/Dataframe: Format string numbers with commas as Thousands Separators

Solution 1:

Solution using apply lambda

import pandas as pd
import numpy as np

def format_float(x):
    try:
       flt = float(x)
       return "{:,}".format(flt)
    except:
       return x

s = {'A': "Hello", 'B': "593753", 'C': "16.8|", "D" : np.nan, "E":"%"}
s = pd.Series(data=s, index=['A', 'B', 'C',"D","E"])

s2 = s.apply(lambda x: format_float(x))