[PYTHON] Extract the maximum value with pandas and change that value

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 add 1 to that 15 and rewrite it to 16.

python


import pandas as pd

#data.Maximum value of csv+1 Function to do
def rewrite_pop():
    # data.Load csv and pop maximum_fur_Store in cou
    df = pd.read_csv('output_files/data.csv', names=['fru_name', 'count', ])
    pop_fur_cou = int(df.iat[df['count'].idxmax(), 1])
    #Pop which is the maximum value_fur_cou+1
    pop_fur_cou += 1
    #Data increased by 1.Overwrite csv
    df.iat[df['count'].idxmax(), 1] = pop_fur_cou
    df.to_csv('output_files/data.csv', index=False, header=False)

rewrite_pop()

python


df.iat[df['count'].idxmax(), 1] = pop_fur_cou

Is

python


df.loc[df["count"].idxmax(), "count"] = pop_fur_cou

May be better. .. ..

Recommended Posts

Extract the maximum value with pandas and change that value
Extract the maximum value with pandas.
Phenomenon that the numerical value changes slightly with Pandas and its response
Describe ec2 with boto3 and retrieve the value
How to extract null values and non-null values with pandas
How to extract non-missing value nan data with pandas
How to extract non-missing value nan data with pandas
[Python] Change dtype with pandas
Extract the xz file with python
[Python3] Save the mean and covariance matrix in json with pandas
Extract specific multiple columns with pandas
I read the Sudachi synonym dictionary with Pandas and searched for synonyms
Extract lines that match the conditions from a text file with python
Find the maximum value python (fixed ver)
[Python] Use pandas to extract △△ that maximizes ○○
This and that of the inclusion notation.
Plot the Nikkei Stock Average with pandas
Import of japandas with pandas 1.0 and above
Find the SHA256 value with R (with bonus)
Grouping csv and getting minimum value (pandas)
Load csv with pandas and play with Index
Read CSV and analyze with Pandas and Seaborn
Extract the Azure SQL Server data table with pyodbc and try to make it numpy array / pandas dataframe
I used gawk to find out the maximum value that goes into NF.
Fill the missing value (null) of DataFrame with the values before and after with pyspark
Talking about the features that pandas and I were in charge of in the project
Extract the color of the object in the image with Mask R-CNN and K-Means clustering
I compared the moving average of IIR filter type with pandas and scipy
[Python] A program that finds the minimum and maximum values without using methods
[Python Tips] How to retrieve multiple keys with the maximum value from the dictionary
Note that the calculation of average pairwise correlation was very easy with pandas
A model that identifies the guitar with fast.ai
Scraping the holojour and displaying it with CLI
Find the mood value with python (Rike Koi)
[Automation] Extract the table in PDF with Python
Note that the Pandas loc specifications have changed
Change the color of Fabric errors and warnings
Can't change aspect_ratio with sympy.plotting? About the matter
Implement "Data Visualization Design # 3" with pandas and matplotlib
Install pip and pandas with Ubuntu or VScode
Analyze Apache access logs with Pandas and Matplotlib
Interactively visualize data with TreasureData, Pandas and Jupyter.
Solving the Lorenz 96 model with Julia and Python
Archive and compress the entire directory with python
The story that fits in with pip installation
[All-new best browser] Let's change the way the Internet works and how it works with the Brave browser.
[Python] Read Japanese csv with pandas without garbled characters (and extract columns written in Japanese)
Extract images and tables from pdf with python to reduce the burden of reporting
How to change the behavior when loading / dumping yaml with PyYAML and its details
I just wanted to extract the data of the desired date and time with Django
I tried to compare the processing speed with dplyr of R and pandas of Python