Recipe: How to format string in a Pandas DataFrame Column?
DATA MUNGING PYTHON PANDAS DATAFRAME PANDAS CHEATSHEET PANDAS DATAFRAME TUTORIAL PANDAS COLUMN

How to format string in a Pandas DataFrame Column?

This recipe helps you format string in a Pandas DataFrame Column
In [1]:
## How to format string in a Pandas DataFrame Column
def Kickstarter_Example_98():
    print()
    print(format('How to format string in a Pandas DataFrame Column','*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # load libraries
    import pandas as pd

    # Create a list of first names
    first_names = pd.Series(['Steve Murrey', 'Jane Fonda',
                             'Sara McGully', 'Mary Jane'])
    print()
    print(first_names)

    # print the column with lower case
    print(); print(first_names.str.lower())

    # print the column with upper case
    print(); print(first_names.str.upper())

    # print the column with title case
    print(); print(first_names.str.title())

    # print the column split across spaces
    print(); print(first_names.str.split(" "))

    # print the column with capitalized case
    print(); print(first_names.str.capitalize())

Kickstarter_Example_98()
****************How to format string in a Pandas DataFrame Column*****************

0    Steve Murrey
1      Jane Fonda
2    Sara McGully
3       Mary Jane
dtype: object

0    steve murrey
1      jane fonda
2    sara mcgully
3       mary jane
dtype: object

0    STEVE MURREY
1      JANE FONDA
2    SARA MCGULLY
3       MARY JANE
dtype: object

0    Steve Murrey
1      Jane Fonda
2    Sara Mcgully
3       Mary Jane
dtype: object

0    [Steve, Murrey]
1      [Jane, Fonda]
2    [Sara, McGully]
3       [Mary, Jane]
dtype: object

0    Steve murrey
1      Jane fonda
2    Sara mcgully
3       Mary jane
dtype: object


Stuck at work?
Can't find the recipe you are looking for. Let us know and we will find an expert to create the recipe for you. Click here
Companies using this Recipe
2 developers from Infosys
1 developer from Candela Labs
1 developer from Fidelity Investments
1 developer from HvH
1 developer from L&T Infotech
1 developer from Renovite Technologies
1 developer from Vodafone
1 developer from Altimetrik
1 developer from Cognizant
1 developer from Gap