#範例16-7:DataFrame的row列索引鍵取值法(index location,iloc)的2維格式:df.iloc[0:3][0:5] = df.iloc[0:3,0:5] #https://www.runoob.com/pandas/pandas-dataframe.html #https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html #(1)檔案:學生成績檔(excel) #https://acupun.site/lecture/python/py_example/chp16/score2.xlsx #(1)重點1: # row列索引鍵取值法,: # (A).格式1:df.iloc[][] # (B).格式2:df.iloc[,] #(2)重點2: # row列索引鍵取值法,: # (A).格式1:df.iloc[0:3][0:5] # (B).格式2:df.iloc[0:3,0:5] # 說明: # (A).編號0可以省略:df.iloc[0:3][0:5] = df.iloc[:3][:5] # (B).最後編號可以省略:df.iloc[0:3][0:5] = df.iloc[0:3][:] # (C).最後的編號,不會執行,只會執行到最後編號-1 #------------------------------ #1.練習1:分析學生成績檔(excel) #--------------------- #(1)讀取網路檔案 import pandas as pd df = pd.read_excel("https://acupun.site/lecture/python/py_example/chp16/score2.xlsx","mad3a") #--------------------- #(2)印出第1個同學的所有欄位:df.iloc[0][0:5]), df.iloc[0,0:5]) print() print("2. 第1位同學的資料=\n") print() print("第1位同學的資料=\n") print() print("第1位同學的資料=\n") print() print("第1位同學的資料=\n") print() #--------------------- #(3)印出第1~3個同學的所有欄位:df.iloc[0:3][0:5], df.iloc[:3,0:5] print() print("3. 第1~3位同學的資料=\n") print() print("第1~3位同學的資料=\n") print() print("第1~3位同學的資料=\n") print() print("第1~3位同學的資料=\n") print() #----------------------------------------------------- #----------------------------------------------------- #範例16-7:DataFrame的row列索引鍵取值法(index location,iloc)的2維格式:df.iloc[0:3][0:5] = df.iloc[0:3,0:5] #https://www.runoob.com/pandas/pandas-dataframe.html #https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html #(1)檔案:學生成績檔(excel) #https://acupun.site/lecture/python/py_example/chp16/score1.xlsx #(1)重點1: # row列索引鍵取值法,: # (A).格式1:df.iloc[][] # (B).格式2:df.iloc[,] #(2)重點2: # row列索引鍵取值法,: # (A).格式1:df.iloc[0:3][0:5] # (B).格式2:df.iloc[0:3,0:5] # 說明: # (A).編號0可以省略:df.iloc[0:3][0:5] = df.iloc[:3][:5] # (B).最後編號可以省略:df.iloc[0:3][0:5] = df.iloc[0:3][:] # (C).最後的編號,不會執行,只會執行到最後編號-1 #------------------------------ #1.練習1:分析學生成績檔(excel) #--------------------- #(1)讀取網路檔案 import pandas as pd df = pd.read_excel("https://acupun.site/lecture/python/py_example/chp16/score2.xlsx","mad3a") #--------------------- #(2)印出第1個同學的所有欄位:df.iloc[0][0:5]), df.iloc[0,0:5]) print() print("第1位同學的資料=\n", df.iloc[0][0:5]) print() print("第1位同學的資料=\n", df.iloc[0][:]) print() print("第1位同學的資料=\n", df.iloc[0,:]) print() print("第1位同學的資料=\n", df.iloc[0,0:5]) print() #--------------------- #(3)印出第1~3個同學的所有欄位:df.iloc[0:3][0:5], df.iloc[:3,0:5] print() print("第1~3位同學的資料=\n", df.iloc[0:3][0:5]) print() print("第1~3位同學的資料=\n", df.iloc[0:3][:]) print() print("第1~3位同學的資料=\n", df.iloc[:3,:]) print() print("第1~3位同學的資料=\n", df.iloc[:3,0:5]) print() #-----------------------------------------------------