In this article, let’s see a Pandas Series program to display palindrome names for IP Class 12. Create a series of a few names and display only palindrome names. Let’s see the complete program.
Topics Covered
Pandas Series program to display palindrome names for IP Class 12 – Output Sample
The output of the program is as follows:
Example
Series:
0 nitin
1 sagar
2 nayan
3 kanak
4 manish
dtype: object
Output:
nitin
nayan
kanak
Explanation: A palindrome name is a name that is read as similar from forward and backward. Few palindrome names malayalam, nun, mom etc.
Read this also:
Pandas Series program to display palindrome names for IP Class 12 – Steps
Follow these steps to complete the program:
- Create a list of names to accept the names
- Create a series
- Traverse a series using for loop
- Store reverse name into a variable
- Use if condition to check name is palindrome or not
- Print the palindrome names
Pandas Series program to display palindrome names for IP Class 12 – Code
#Write a program to create a series of names and display palindrome names.
import pandas as pd
#list of names
l=['nitin','sagar','nayan','kanak','manish']
#Creating Series
s=pd.Series(l)
#Printing Series
print(s)
#output
print("Output")
#Traversing series, storing reverse name into t variable
#Comparing original names and reverse names
for i in range(len(s)):
t=s[i][::-1]
if s[i]==t:
print(s[i])
Output:
Follow this link for more pandas programs: