How to format string in a Pandas DataFrame Column?
DATA MUNGING DATA CLEANING PYTHON MACHINE LEARNING RECIPES PANDAS CHEATSHEET     ALL TAGS

How to format string in a Pandas DataFrame Column?

How to format string in a Pandas DataFrame Column?

This recipe helps you format string in a Pandas DataFrame Column

0
This python source code does the following : 1. Creates a pandas series 2. Converts strings into lower and upper format 3. performs splits and capitalization
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

Relevant Projects

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

Deep Learning with Keras in R to Predict Customer Churn
In this deep learning project, we will predict customer churn using Artificial Neural Networks and learn how to model an ANN in R with the keras deep learning package.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

Solving Multiple Classification use cases Using H2O
In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

Predict Census Income using Deep Learning Models
In this project, we are going to work on Deep Learning using H2O to predict Census income.

Forecast Inventory demand using historical sales data in R
In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

Sequence Classification with LSTM RNN in Python with Keras
In this project, we are going to work on Sequence to Sequence Prediction using IMDB Movie Review Dataset​ using Keras in Python.