# using pandas DataFrame
ser_df = pd.DataFrame(ser1, ser2).reset_index()
ser_df.head()# using pandas DataFrame with a dictionary, gives a specific name to the column
ser_df = pd.DataFrame({"col1":ser1,"col2":ser2})
ser_df.head()# using pandas concat
ser_df = pd.concat([ser1, ser2], axis =1)
ser_df
0
1
0
a
0
1
b
1
2
c
2
3
e
3
4
d
4
5
f
5
6
g
6
7
h
7
8
i
8
9
j
9
10
k
10
11
l
11
12
m
12
13
n
13
14
o
14
15
p
15
16
q
16
17
r
17
18
s
18
19
t
19
20
u
20
21
v
21
22
w
22
23
x
23
24
y
24
25
z
25
5. 计算ser的最小值、第25%位数、中位数、第75%位数和最大值
#输入
state = np.random.RandomState(100)
ser = pd.Series(state.normal(10,5,25))print(ser)
#输入
p = pd.Series([1,2,3,4,5,6,7,8,9,10])
q = pd.Series([10,9,8,7,6,5,4,3,2,1])'''
应该输出
18.165
'''
'\n应该输出\n\n18.165\n'
# using list comprehension
suma = np.sqrt(np.sum([(p - q)**2for p, q inzip(p, q)]))
suma
# using series one to one operationsum((p - q)**2)**.5# using numpy
np.linalg.norm(p-q)
#输入# input
ser = pd.Series(np.logspace(-2,2,30))
ser
ser = ser.to_frame()# ser.ix[ser['0']<=np.percentile(ser,5),'0']=np.percentile(ser,5)# ser.ix[ser[0]>=np.percentile(ser,95),0]=np.percentile(ser,95)# df.sex[df['sex']=='m']=1# ser.'0'[ser[0]<=np.percentile(ser,5)]=np.percentile(ser,5)# df.loc[(df['First Season'] > 1990)] = 1
ser.loc[(ser[0]<=np.percentile(ser,5))]= np.percentile(ser,5)
ser.loc[(ser[0]>=np.percentile(ser,95))]= np.percentile(ser,95)
ser
# 参考:# http://www.cocoachina.com/cms/wap.php?action=article&id=53695# https://blog.csdn.net/brucewong0516/article/details/80205422# https://blog.csdn.net/weixin_41100555/article/details/88555658# https://blog.csdn.net/weixin_37536446/article/details/81266273
0
0
0.016049
1
0.016049
2
0.018874
3
0.025929
4
0.035622
5
0.048939
6
0.067234
7
0.092367
8
0.126896
9
0.174333
10
0.239503
11
0.329034
12
0.452035
13
0.621017
14
0.853168
15
1.172102
16
1.610262
17
2.212216
18
3.039195
19
4.175319
20
5.736153
21
7.880463
22
10.826367
23
14.873521
24
20.433597
25
28.072162
26
38.566204
27
52.983169
28
63.876672
29
63.876672
10. 从文件list.xlsx读取数据,统计每个学校的人数。
# -*- coding:utf-8 -*-import pandas as pd
# 从文件list.xlsx读取数据,统计每个学校的人数
df = pd.read_excel('list.xlsx')# 这个会直接默认读取到这个Excel的第一个表单# data=df.head()#默认读取前5行的数据 在()里可以加数字表示多少行# data=df.iloc[0:].values#0表示第一行 这里读取数据并不包含表头,要注意哦!# print("读取指定行的数据:\n{0}".format(data))
data = df.iloc[:,4].values
# print("读取指定列的数据:\n{0}".format(data))
setAll =set()for i in data:
setAll.add(i)dict={}for i in setAll:dict[i]=0for i in data:dict[i]+=1for i indict.items():print(i)# ix报错参考:https://blog.csdn.net/Jinnnnnny/article/details/106670768