June 4, 2024, 7:02 p.m. | saim

DEV Community dev.to

There are two main ways to capitalize strings in a pandas DataFrame:

1. str.capitalize():

This method capitalizes the first letter of each word in a string element.

import pandas as pd

# Create a DataFrame
df = pd.DataFrame({'text': ['hello world', 'python programming', 'pandas']})

# Capitalize the first letter of each word
df['text'] = df['text'].str.capitalize()


2. Vectorized string methods:

You can achieve capitalization using vectorized string methods like .str.upper() for uppercase and string slicing for selecting the first character.

import …

create dataframe datascience element hello hello world import pandas programming python string strings text webdev word world

Senior Data Engineer

@ Displate | Warsaw

Junior Data Analyst - ESG Data

@ Institutional Shareholder Services | Mumbai

Intern Data Driven Development in Sensor Fusion for Autonomous Driving (f/m/x)

@ BMW Group | Munich, DE

Senior MLOps Engineer, Machine Learning Platform

@ GetYourGuide | Berlin

Data Engineer, Analytics

@ Meta | Menlo Park, CA

Data Engineer

@ Meta | Menlo Park, CA