Removing higher value from line with for

Asked

Viewed 34 times

-2

Good afternoon,

I’m trying to extract the largest whole value from every line of my dataframe. I created the following code for this:

for i in df.index:
    df["maxx"] = df.loc[i].max()
    df["minn"] = df.loc[i].min()

The expected result was to generate two columns in the dataframe (df["maxx"] e df["minn"]) with the following values: max line 1 = 23 min line 1 = 3 max line 2 = 78 min line 2 = 2

But the result found is: max line 1 = 78 min line 1 = 2 max line 2 = 78 min line 2 = 2

What should I change in my code to consider max and min per line and not the total dataframe?

1 answer

0

I managed to solve my problem using the code below:

for i in df.index:
    df["maxx"] = df.max(axis = 1)
    df["minn"] = df.min(axis = 1)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.