我尝试使用以下数据读取文本文件并说明其数据类型:
这是txt文件中的数据
9yr14z1jdnh01ou8d38 , rcsfhuivhqgpgabxd, szumg5l7lyc30wimkah4, 1345, yfeporesumr, 1313.670598592, 1384.35266, gklxmzulyylpuhkabawhuhtcxjy, ugwulzqwhld, 8422, 8728.054385, 1675, 9xuxp5l7trq50l6psgw058aqacs9n , 2080.01345, ppznnnmherwktxugprysryj, 4295, 6992, g0aa4yh2btxc6ta959p9o
输出应该是这样的:
youruasdifafasd - alphabetical strings
127371237 - integer
asdfka12348fas - alphanumeric
13123.123 - real numbers
asjdfklasdjfklaasf - alphabetical strings
123192u3kjwekhf - alphanumeric
我试图显示他们的数据类型,但这是我的错误:
AttributeError:“列表”对象没有属性“isalpha”
到目前为止,这是我的代码:
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")