1、创建一个Series对象
import numpy as np
import pandas as pd
score = pd.Series(data=[90,95,85,78,np.NAN,96,94,np.NAN,80,87,86,83],index=range(1,13),name='score')
score.index.name = "class"
score
class
1 90.0
2 95.0
3 85.0
4 78.0
5 NaN
6 96.0
7 94.0
8 NaN
9 80.0
10 87.0
11 86.0
12 83.0
Name: score, dtype: float64
2、查看1-5班的成绩
score[1:5]
class
2 95.0
3 85.0
4 78.0
5 NaN
Name: score, dtype: float64
3、查看哪个班级的成绩没有录入
score[score.isnull()]
class
5 NaN
8 NaN
Name: score, dtype: float64
4、获取11班的成绩
score[11]
86.0
5、在每个人的成绩加5分
score + 5
class
1 95.0
2 100.0
3 90.0
4 83.0
5 NaN
6 101.0
7 99.0
8 NaN
9 85.0
10 92.0
11 91.0
12 88.0
Name: score, dtype: float64
6、找出成绩在90分以上的班级
score[score > 90]
class
2 95.0
6 96.0
7 94.0
Name: score, dtype: float64
1、创建一个DataFrame
DataFrame:
data = {
"姓名":['张三','李四','王五','小明','小红','小刚','小亮'],
"语文":[89,78,79,89,90,87,83],
"数学":[59,83,85,92,67,81,77],
"英语":[84,97,88,83,67,73,71],
"体育":[0,0,0,0,0,0,0]
}
df = pd.DataFrame(data)
df
![@@SOXVSVBI4%YAD_WQE{`V.png
2、进行转置
df.T
df.transpose()
a = df.transform() #用来干什么的?怎么用
3、删除掉体育成绩
df.drop(['体育'],axis=1)
df.T.drop(['体育'])
del(df['体育'])
df
4、新增综合成绩
s = pd.DataFrame({"综合":[88,89,85,86,85,86,74]})
s
df.T.append(s.T) #这个虽然实现了但是有疑问还需要详细分析
df["综合"]=[88,89,85,86,85,86,74]
df
df1 = df.T
df1
df1.loc["综合"]=[88,89,85,86,85,86,74]
df1
df.insert(1,'综合',[88,89,85,86,85,86,74], allow_duplicates=False)
df