简体   繁体   English

如何根据另一列的最小值创建新列

[英]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.

相关问题 根据列表中的另一列内容创建新的列值 - Create a new column value based on another column content from a list 根据另一列的值创建新列 - Create new column based on value of another column 根据另一列中的值创建新列 - Create a new column based on value in another column 如何根据数据框的另一列中的条件查找列中的最小值? - How to find minimum value in a column based on condition in an another column of a dataframe? 如何使用python中另一列的值创建一个新列 - How to create a new column with a value from another column in python 根据一列的条件和熊猫中另一列的值创建新列 - Create new column based on condition from one column and the value from another column in pandas 如何使用 pandas 根据第三列中的值创建一个包含来自一列或另一列的值的新列? - How do I create a new column with values from one column or another based on the value in a third column using pandas? 如何在 Pandas 中创建一个新列并根据现有列中的条件值向该新列添加值? - How to create a new column in pandas and add value to that new column based on the conditional value from the existing column? 如果值落在一个范围内,则根据另一列的条件创建新列 - Create new column based on condition of another column if value falls in a range 根据数据框中另一列的值创建新列 - Create new column based on a value of another column in a data-frame
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM