find the max of row x in a dataset in python

Assuming your dataset is a pandas DataFrame and you want to find the maximum value of row x, you can use the .loc accessor to select that row and the .max() method to find its maximum value. Here's an example:

main.py
import pandas as pd

# create a sample dataset
df = pd.DataFrame({
    'A': [1, 2, 3],
    'B': [4, 5, 6],
    'C': [7, 8, 9]
})

# find the maximum value of row 0
max_value = df.loc[0].max()

print(max_value)  # 7
215 chars
14 lines

In this example, we first create a DataFrame with three columns and three rows. Then we use .loc[0] to select the first row (rows are 0-indexed in pandas). Finally, we call the .max() method to find the maximum value of that row, which is 7.

related categories

gistlibby LogSnag