[英]How to create a new column based on minimum value from another column
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我有一个 dataframe 有很多列和行(> 10000),但我需要根据另一个列的最小值创建一个列
Example dataframe:示例 dataframe:
enter image description here在此处输入图像描述
So, I need the column "Cantidad min"
to contain the minimum value for that group of "CodProducto"
:因此,我需要"Cantidad min"
列包含该组"CodProducto"
的最小值:
Example:例子:
enter image description here在此处输入图像描述
How can I do in python?在 python 怎么办?
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.如果它不起作用,请将您的数据提供为.csv 格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.