Pandas is a Python data analysis library. Installation is `` `pip install pandas```
sample.py
import pandas as pd
xxx = pd.read_csv('sample.csv') #xxx is an appropriate variable
print (xxx) #Output of all columns
sample.csv
If you want to output the student number with the highest score in sample.csv
sample2.py
import pandas as pd
filename = pd.read_csv('sample.csv',encoding="SHIFT-JIS")#Or UTF-8
listA = []
listB = []
listA = filename['student number']
listB = filename['Score']
max=0
leng = len(listA)
for n in range(leng):
if listB[n]>max:
max=listB[n]
num = n
print ('The student number with the highest score is'+str(listA[num]))
Pandas is convenient because you can easily read Excel files such as csv. If you want to analyze data using python from now on, why not use it?
Recommended Posts