f = open("routeviews-rv2-20181110-1200.pfx2as", 'r')
#read file into array, ignore first 6 lines
lines = loadtxt("routeviews-rv2-20181110-1200.pfx2as", dtype='str',
delimiter="\t", unpack=False)
#convert to dataframe
df = pd.DataFrame(lines,columns=['IPPrefix', 'PrefixLength', 'AS'])
series = df['AS'].astype(str).str.replace('_', ',').str.split(',')
arr = numpy.array(list(chain.from_iterable(series)))
ASes= pd.Series(numpy.bincount(arr))
ValueError:基数为10的int()的文本无效:“31133\u 6550065501”
我想计算每次一个项目出现在列为。但是,有些行有多个条目需要计数。你知道吗
参考:Python Find max in dataframe column to loop to find all values
Txt文件:http://data.caida.org/datasets/routing/routeviews-prefix2as/2018/11/
但这不能算下面的67820行。你知道吗
Out[94]: df=
A B C
0 1.0.0.0 24 13335
1 1.0.4.0 22 56203
2 1.0.4.0 24 56203
3 1.0.5.0 24 56203
... ... ...
67820 1.173.142.0 24 31133_65500,65501
... ... ...
778719 223.255.252.0 24 58519
778720 223.255.254.0 24 55415
不是打字错误,这是它在文件中的显示方式。你知道吗
Desired output.
1335 1
... ..
31133 1
... ..
55415 1
... ..
56203 3
... ..
58159 1
... ..
65500 1
65501 1
... ..
^{} +^{} +^{}
您可以用
,
替换_
,在使用np.bincount
之前先拆分然后链接:相关问题 更多 >
编程相关推荐