First, In a directory (folder) called output_files Create a csv file named data.csv.
The contents are apple, 4 banana, 5 orange, 15 It has become.
data.csv
apple, 4
banana, 5
orange, 15
From this csv file Extract 15 with the largest number, The goal is to output the orange that is written together in a certain column of 15.
main
import pandas as pd
#data.Read cs as df.
#The name of the 0th column is fru_name, the name in the first column is count.
df = pd.read_csv('output_files/data.csv', names=['fru_name', 'count',])
#df(data.What read csv)Is output as it is.
print(df)
print('####################')
#Output the index with the maximum value of count.
print(df['count'].idxmax())
print('####################')
#Output the 0th column of index with the maximum value of count.
print(df.iat[df['count'].idxmax(), 0])
print('####################')
Execution result
fru_name count
0 apple 4
1 banana 5
2 orange 15
####################
2
####################
orange
Recommended Posts