import numpy
# 1.创建数组
data = numpy.array(range(10))
print(data)
打印结果:
[0 1 2 3 4 5 6 7 8 9]
import string
# 2.创建索引
index = list(string.ascii_uppercase[:10])
print(index)
打印结果:
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
import pandas
# 3.创建Series一维数组
t = pandas.Series(data, index=index)
print(t)
打印结果:
A 0
B 1
C 2
D 3
E 4
F 5
G 6
H 7
I 8
J 9
dtype: int64
print(t.index) # 打印索引
print('*' * 50)
print(t.values) # 打印数组
print('*' * 50)
print(t.value_counts()) # 统计元素个数
打印结果:
Index(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'], dtype='object')
**************************************************
[0 1 2 3 4 5 6 7 8 9]
**************************************************
9 1
8 1
7 1
6 1
5 1
4 1
3 1
2 1
1 1
0 1
dtype: int64