# -*- coding:gbk -*-
import urllib.request
import sys
url='http://archive.ics.uci.edu/ml/machine-learning-databases/undocumented/connectionist-bench/sonar/sonar.all-data'
data=urllib.request.urlopen(url)
rowlist=[]
labels=[]
for line in data:
row=str(line).strip().split(',')
rowlist.append(row)
nrow=len(rowlist)
ncol=len(rowlist[1])
type=[0]*3
colcounts=[]
for col in range(ncol):
for row in rowlist:
try:
a=float(row[col])
if isinstance(a,float):
type[0]+=1
except ValueError:
if len(row[col])>0:
type[1]+=1
else:
type[2]+=1
colcounts.append(type)
type=[0]*3
print("col"+"\t"+"number"+"\t"+"strings"+"\t "+"other\n")
icol=0
for types in colcounts:
print(str(icol)+'\t '+str(types[0])+'\t '+str(types[1])+'\t '+str(types[2])+'\n')
icol+=1
python机器学习-数据类型统计
最新推荐文章于 2024-02-04 19:13:26 发布