Python Pandas Max value

We previously discussed getting the powerful python library Pandas up and running. In this section, we shall start looking at how this library can help us understand our data.

Our first example will be to use the max() function to find the largest id currently used in our dataset. This helps us with our index strategies in our ongoing database example.

Python using Laptop

Consider our example csv file, which we are reading in path pandas. Note that the id value is intentionally not in order to help demonstrate we are not just returning the row number

id,colour,weight,type,quantity
1,blue,finger,wool,22.0
2,green,finger,wool,4.0
3,blue,sock,wool-blend,20.0
6,black,chunky,acrylic,35.0
7,white,chunky,acrylic,11.0
10,white,finger,wool,10.0
9,yellow,sock,wool-blend,5.0

If we make a call to this function

def highestIndexInDB():
  df = pd.read_csv(database)
  return df.max()["id"]

print(highestIndexInDB())
> python printIndex.py
10