Pandas Series program to display palindrome names for IP Class 12

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.

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:

Python series program to display palindrome numbers

Pandas Series program to display palindrome names for IP Class 12 – Steps

Follow these steps to complete the program:

  1. Create a list of names to accept the names
  2. Create a series
  3. Traverse a series using for loop
  4. Store reverse name into a variable
  5. Use if condition to check name is palindrome or not
  6. 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:

Pandas Series program to display palindrome names for IP Class 12

Follow this link for more pandas programs:

Pandas Series Practical Program

Leave a Reply