Skip to content

Instantly share code, notes, and snippets.

@Celia-code
Created March 11, 2020 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Celia-code/cc8d471c68cd15a1f6c18aab1393258b to your computer and use it in GitHub Desktop.
Save Celia-code/cc8d471c68cd15a1f6c18aab1393258b to your computer and use it in GitHub Desktop.
This is for pandas
import pandas as pd
#
data = pd.DataFrame({
"name":["Amy", "Bob", "Chole"],
"score":[100, 80, 69]
})
#1.計算三位學生的成績平均值
score = data["score"]
print("成績平均值:", score.mean())
#2.在欄位中新增一欄,內容為學生的操行成績
data["grade"] = ["C", "A", "B+"]
print(data)
#打印出
"""
成績平均值: 83.0
name score grade
0 Amy 100 C
1 Bob 80 A
2 Chole 69 B+
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment