Python Practice › Pandas Programs › Program 25

Capitalise first and last letters

EasyPandas Programs · 25 of 95

Write a pandas program to make the first and last letter of each word uppercase.

Advertisement
Input
["sqatools", "python", "data", "science"]
Output
0    SqatoolS
1      PythoN
2        DatA
3     SciencE
dtype: str

Approach

  1. map a small function.

Solution

Python
import pandas as pds = pd.Series(["sqatools", "python", "data", "science"])print(s.map(lambda w: w[0].upper() + w[1:-1] + w[-1].upper()))
Output
0    SqatoolS
1      PythoN
2        DatA
3     SciencE
dtype: str
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs