1、创建一个Series对象

  1. import numpy as np
  2. import pandas as pd
  3. score = pd.Series(data=[90,95,85,78,np.NAN,96,94,np.NAN,80,87,86,83],index=range(1,13),name='score')
  4. score.index.name = "class"
  5. score
  1. class
  2. 1 90.0
  3. 2 95.0
  4. 3 85.0
  5. 4 78.0
  6. 5 NaN
  7. 6 96.0
  8. 7 94.0
  9. 8 NaN
  10. 9 80.0
  11. 10 87.0
  12. 11 86.0
  13. 12 83.0
  14. Name: score, dtype: float64

2、查看1-5班的成绩

  1. score[1:5]
  1. class
  2. 2 95.0
  3. 3 85.0
  4. 4 78.0
  5. 5 NaN
  6. Name: score, dtype: float64

3、查看哪个班级的成绩没有录入

  1. score[score.isnull()]
  1. class
  2. 5 NaN
  3. 8 NaN
  4. Name: score, dtype: float64

4、获取11班的成绩

  1. score[11]
  1. 86.0

5、在每个人的成绩加5分

  1. score + 5
  1. class
  2. 1 95.0
  3. 2 100.0
  4. 3 90.0
  5. 4 83.0
  6. 5 NaN
  7. 6 101.0
  8. 7 99.0
  9. 8 NaN
  10. 9 85.0
  11. 10 92.0
  12. 11 91.0
  13. 12 88.0
  14. Name: score, dtype: float64

6、找出成绩在90分以上的班级

  1. score[score > 90]
  1. class
  2. 2 95.0
  3. 6 96.0
  4. 7 94.0
  5. Name: score, dtype: float64

1、创建一个DataFrame

DataFrame:

  1. data = {
  2. "姓名":['张三','李四','王五','小明','小红','小刚','小亮'],
  3. "语文":[89,78,79,89,90,87,83],
  4. "数学":[59,83,85,92,67,81,77],
  5. "英语":[84,97,88,83,67,73,71],
  6. "体育":[0,0,0,0,0,0,0]
  7. }
  8. df = pd.DataFrame(data)
  9. df

![@@SOXVSVBI4%YAD_WQE{`V.png

2、进行转置

  1. df.T

image.png

  1. df.transpose()

image.png

  1. a = df.transform() #用来干什么的?怎么用

3、删除掉体育成绩

  1. df.drop(['体育'],axis=1)

image.png

  1. df.T.drop(['体育'])

image.png

  1. del(df['体育'])
  2. df

image.png

4、新增综合成绩

  1. s = pd.DataFrame({"综合":[88,89,85,86,85,86,74]})
  2. s

image.png

  1. df.T.append(s.T) #这个虽然实现了但是有疑问还需要详细分析

image.png

  1. df["综合"]=[88,89,85,86,85,86,74]
  2. df

image.png

  1. df1 = df.T
  2. df1

image.png

  1. df1.loc["综合"]=[88,89,85,86,85,86,74]
  2. df1

image.png

  1. df.insert(1,'综合',[88,89,85,86,85,86,74], allow_duplicates=False)
  2. df

image.png