How to format string in a Pandas DataFrame Column?
0

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