I tried to read a text file with this following data and state its data type:
This is the data in the txt file
9yr14z1jdnh01ou8d38 , rcsfhuivhqgpgabxd, szumg5l7lyc30wimkah4, 1345, yfeporesumr, 1313.670598592, 1384.35266, gklxmzulyylpuhkabawhuhtcxjy, ugwulzqwhld, 8422, 8728.054385, 1675, 9xuxp5l7trq50l6psgw058aqacs9n , 2080.01345, ppznnnmherwktxugprysryj, 4295, 6992, g0aa4yh2btxc6ta959p9o
The output should be like this:
youruasdifafasd - alphabetical strings
127371237 - integer
asdfka12348fas - alphanumeric
13123.123 - real numbers
asjdfklasdjfklaasf - alphabetical strings
123192u3kjwekhf - alphanumeric
I tried to display their datatype but then this is the error I:
AttributeError: 'list' object has no attribute 'isalpha'
This is my code so far:
import numbers
import os
import string
import pandas as pd
data = []
with open('output.txt') as file:
for row in file:
# row = row.strip()
row = row.replace(" ", "")
data.append(row.split(","))
# print(data)
for x in data:
# print (x)
if x.isalpha():
print (x + " - alphabetical strings")
elif x.isalnum():
print (x + " - alphanumeric")
elif isinstance(x, numbers.Integral):
print (x + " - integer")
else:
print (x + " - float")