![](https://img2018.cnblogs.com/i-beta/1020928/201912/1020928-20191212175239451-520569666.png)
import pandas as pd
datas = [[65,92,78,83,70], [90,72,76,93,56], [81,85,91,89,77], [79,53,47,94,80]]
indexs = ["林大明", "陈聪明", "黄美丽", "熊小娟"]
columns = ["语文", "数学", "英文", "自然", "社会"]
df = pd.DataFrame(datas, columns=columns, index=indexs)
print('df["自然"] ->')
print(df["自然"])
![](https://img2018.cnblogs.com/i-beta/1020928/201912/1020928-20191212175529997-692745572.png)
若要读取两个以上列数据,则需用两个中括号把列标题括起来,语法为 :
![](https://img2018.cnblogs.com/i-beta/1020928/201912/1020928-20191212175622600-306226839.png)
print('df[["语文", "数学", "自然"] ->')
print(df[["语文", "数学", "自然"]])
![](https://img2018.cnblogs.com/i-beta/1020928/201912/1020928-20191212175722182-530892213.png)
我们还可以通过对列数据进行逻辑运算来读取数据,例如读取数学成绩 80 分以
上(含)的所有学生成绩:
print('df[df.数学>=80] ->')
print(df[df.数学 >= 80])
![](https://img2018.cnblogs.com/i-beta/1020928/201912/1020928-20191212175820118-1547116443.png)
用 df.values 读取数据
df.values 可读取全部数据,返回结果是一个二维列表 ,执行结果为 :
import pandas as pd
datas = [[65,92,78,83,70], [90,72,76,93,56], [81,85,91,89,77], [79,53,47,94,80]]
indexs = ["林大明", "陈聪明", "黄美丽", "熊小娟"]
columns = ["语文", "数学", "英文", "自然", "社会"]
df = pd.DataFrame(datas, columns=columns, index=indexs)
print("df.values:")
print(df.values)
![](https://img2018.cnblogs.com/i-beta/1020928/201912/1020928-20191212175949245-660403468.png)
print("陈聪明的成绩(df.values[1]):")
print(df.values[1])
![](https://img2018.cnblogs.com/i-beta/1020928/201912/1020928-20191212180052044-579731663.png)
读取第 2 位学生陈聪明的英文成绩(第 3 个科目〉的语法为 :
print("陈聪明的英文成绩(df.values[1][2]):")
print(df.values[1][2])
![](https://img2018.cnblogs.com/i-beta/1020928/201912/1020928-20191212180148090-492931749.png)