How to create a new column based on minimum value from another column

Question:

I have a dataframe with a lot of columns and rows (> 10000), but I need to create a column based on the minimum value from another one

Example dataframe:

enter image description here

So, I need the column "Cantidad min" to contain the minimum value for that group of "CodProducto":

Example:

enter image description here

How can I do in python?

Asked By: Aleja Gallo

||

Answers:

Please try follow one.

dataframe["Cantidad min"] = df.groupby(dataframe)["CodProducto"].min()

I can’t test this code on your data because you didn’t share yours. If it doesn’t works, please provide me your data as .csv format.

Answered By: Levin
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.