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