[Python combat basics] How does Pandas calculate the row where the maximum and minimum values are located

Table of contents

1. The actual combat scene

2. Main points of knowledge

file read and write

Basic grammar

Pandas

iloc

argmax

Three, rookie combat

1. Create a python file

2. Running results 


1. The actual combat scene

Actual combat scenario: How does Pandas calculate the row where the maximum and minimum values ​​are located

2. Main points of knowledge

  • file read and write

  • Basic grammar

  • Pandas

  • iloc

  • argmax

Three, rookie combat

Schedule now!

1. Create a python file

import pandas as pd

df = pd.read_json('market.json')

# pct_change形如:(+1.47%)
#转换成数字类型
df['pct_change'] = df['pct_change'].apply(  lambda item: float(item[1:-2]))

#argmax最大值的索引,df.iloc可以获取这行的数据
print(df.iloc[df["pct_change"].argmax()])
print()
print(df.iloc[df["pct_change"].argmin()])

2. Running results 

profile            ^FTSE100 (Wielka Brytania)
time                                    14:12
price                                 5945.44
change                                 115.98
pct_change                               1.99
reference_price                       5829.46
open                                  5829.46
low                                   5829.46
high                                  5974.88
Name: 7, dtype: object

profile            ^ATXC (Grecja)
time                        14:13
price                      621.82
change                       -2.8
pct_change                  -0.45
reference_price            624.62
open                       627.48
low                        621.82
high                        631.7
Name: 2, dtype: object

Rookie combat, keep learning!  

Guess you like

Origin blog.csdn.net/qq_39816613/article/details/126252107