Write a program in Python to verify kth index element is either alphabet or number in a given series

PythonPandasServer Side ProgrammingProgramming

Input − Assume, you have a Series,

a    abc
b    123
c    xyz
d    ijk

Solution

To solve this, we will follow the steps given below −

  • Define a Series

  • Get the index from user

  • Set the if condition to check the value is digit or not. It is defined below,

if(data[x].isdigit()):
   print("digits present")
else:
   print("not present")

Example

Let us see the following implementation to get a better understanding.

import pandas as pd
dic = {'a':'abc','b':'123','c':'xyz','d':'ijk'}
data = pd.Series(dic)
x = input("enter the index : ")
if(data[x].isdigit()):
   print("digits present")
else:
   print("not present")

Output

enter the index : a
not present
enter the index : b
digits present
raja
Published on 10-Feb-2021 13:05:56
Advertisements