Search code examples
pythondataframeuppercasecapitalizetoupper

Convert first 2 letters of all records to Uppercase in python


I have a dataframe DF with just 1 column and I want to uppercase first 2 letters of all the records in python. how do I do that ?


Solution

  • You may use map and Convert you data as you required:

    try below:

    import pandas as pd 
    df = pd.DataFrame({'name':['geeks', 'gor', 'geeks', 'is','portal', 'for','geeks']})
    df['name']=df['name'].map(lambda x: x[:2].upper()+x[2:])
    print (df)
    

    output:

         name
    0   GEeks
    1     GOr
    2   GEeks
    3      IS
    4  POrtal
    5     FOr
    6   GEeks
    

    demo