Q:

Write a Pandas program convert the first and last character of each word to upper case in each word of a given series

0

Write a Pandas program convert the first and last character of each word to upper case in each word of a given series.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import pandas as pd
series1 = pd.Series(['php', 'python', 'java', 'c#'])
print("Original Series:")
print(series1)
result = series1.map(lambda x: x[0].upper() + x[1:-1] + x[-1].upper())
print("\nFirst and last character of each word to upper case:")
print(result)

Sample Output:

Original Series:
0       php
1    python
2      java
3        c#
dtype: object

First and last character of each word to upper case:
0       PhP
1    PythoN
2      JavA
3        C#
dtype: object

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now