[PYTHON] Extract the maximum value with pandas.

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

Extract the maximum value with pandas.
Extract the maximum value with pandas and change that value
How to extract non-missing value nan data with pandas
How to extract non-missing value nan data with pandas
Extract specific multiple columns with pandas
Find the maximum value python (fixed ver)
Find the SHA256 value with R (with bonus)
Phenomenon that the numerical value changes slightly with Pandas and its response
Missing value pandas
Find the mood value with python (Rike Koi)
[Automation] Extract the table in PDF with Python
Describe ec2 with boto3 and retrieve the value
Function to extract the maximum and minimum values ​​in a slice with Go
[Python Tips] How to retrieve multiple keys with the maximum value from the dictionary
Find the maximum Python
Extract the table of image files with OneDrive & Python
Quickly visualize with Pandas
Processing datasets with pandas (1)
Bootstrap sampling with Pandas
Find the sum of unique values with pandas crosstab
Convert 202003 to 2020-03 with pandas
Processing datasets with pandas (2)
Merge datasets with pandas
Extract N samples for each group with Pandas DataFrame
Learn Pandas with Cheminformatics
Take the value of SwitchBot thermo-hygrometer with Raspberry Pi
Log the value of SwitchBot thermo-hygrometer with Raspberry Pi
How to extract null values and non-null values with pandas
Data visualization with pandas
Extract files from EC2 storage with the scp command
Data manipulation with Pandas!
Shuffle data with pandas
Extract the band information of raster data with python
Extract EXIF with sips
Create a new csv with pandas based on the local csv
Memo to get the value on the html-javascript side with jupyter
Check what line caused the error with apply () (dataframe, Pandas)
Calculate the time difference between two columns with Pandas DataFrame
Your URL didn't respond with the value of the challenge parameter.
Find the index of the maximum value (minimum value) of a multidimensional array
Reformat the timeline of the pandas time series plot with matplotlib
Multiply the x-axis value by n when plotting with pylab
Extract the value of dict or list as a string
The true value of Terraform automation starting with Oracle Cloud
Extract the value closest to a value from a Python list element
Try to extract the features of the sensor data with CNN
Extract non-numeric elements with pandas.DataFrame
Read csv with python pandas
Load nested json with pandas
Extract the Azure service list
Insert the debugger with nose
Extract Twitter data with CSV
Kill the process with sudo kill -9
[Python] Change dtype with pandas
Guess the password with klee
gethostbyaddr () communicates with the outside
Extract numbers with regular expressions
Standardize by group with pandas
scraping the Nikkei 225 with playwright-python
Check the code with flake8
Calibrate the model with PyCaret