Python Forum
How can i get the top smallest and top highest value for each row in pandas?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can i get the top smallest and top highest value for each row in pandas?
#5
To find the smallest and largest values in each row of a pandas DataFrame, you can use the min() and max() functions along the appropriate axis. Here's how:

python
Copy code
import pandas as pd

# Create a sample DataFrame
data = {'A': [1, 2, 3],
'B': [4, 5, 6],
'C': [7, 8, 9]}

df = pd.DataFrame(data)

# Find the smallest value in each row
smallest_values = df.min(axis=1)

# Find the largest value in each row
largest_values = df.max(axis=1)

print("Smallest values in each row:")
print(smallest_values)

print("\nLargest values in each row:")
print(largest_values)
This will output the smallest and largest values for each row in the DataFrame.
Pedroski55 likes this post
Reply


Messages In This Thread
RE: How can i get the top smallest and top highest value for each row in pandas? - by marythodge4 - Jun-03-2024, 07:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Read directory listing of files and parse out the highest number? cubangt 5 5,117 Sep-28-2022, 10:15 PM
Last Post: Larz60+
  Find the highest value of a list Menthix 4 2,819 Oct-29-2021, 02:32 PM
Last Post: Menthix
  Sorting numbers from smallest to biggest Dokugan 2 2,921 Apr-14-2020, 09:24 PM
Last Post: Larz60+
  smallest Cosine distance in Graph vino689 3 3,133 Jan-12-2020, 08:06 AM
Last Post: rmspacedashrf
  Filter only highest version of list with alpanumeric names Haasje 6 3,727 Aug-31-2019, 10:17 AM
Last Post: perfringo
  I want to check for the smallest value entered by the user Shilpa 2 2,539 Aug-13-2019, 12:06 PM
Last Post: ThomasL
  Getting the key for the highest value in a dict - how does this code work? rogfrich 4 4,244 Nov-27-2018, 07:05 PM
Last Post: rogfrich
  How do I calculate the smallest value that is recognized as a difference when compari AFoeee 1 3,592 Oct-28-2018, 10:48 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020