简体   繁体   English

如何更改熊猫数据框中某个类别的另一列中的值?

[英]How to change the value in another column of a certain category in a pandas dataframe?

I'm currently working on a dataframe and in a certain column I have different categories of classes (organism taxonomy).我目前正在研究一个数据框,并且在某个列中我有不同类别的类(生物分类法)。 In this class column there are 105 unique classes in the +/- 3000 rows.在这个类列中,+/- 3000 行中有 105 个独特的类。 You can view each row as a species.您可以将每一行视为一个物种。 Multiple species can belong to 1 class.多个物种可以属于 1 个类。

For the class "Unknown" in this class column, I would like to change the value of the column "Superkingdom_name" in each of the rows which have "Unknown" in the class column.对于此类列中的“Unknown”类,我想更改类列中具有“Unknown”的每一行中“Superkingdom_name”列的值。 How is this done?这是怎么做的?

I'm currently clueless of how to do this.我目前不知道如何做到这一点。

So I expect to change the value of "Superkingdom_name" for every row that has value "unknown" in the class column.因此,我希望为类列中具有“未知”值的每一行更改“Superkingdom_name”的值。

Thanks!谢谢!

With the very limited information you have provided, I think you can use loc method.由于您提供的信息非常有限,我认为您可以使用loc方法。 Assuming your data is stored in a df :假设您的数据存储在df

df.loc[df['class'] == "Unknown", 'Superkingdom_name'] = "new_value"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据 Pandas 中的另一个 DataFrame 更改 DataFrame 特定列中的值 - How to change values in certain column of DataFrame based on another DataFrame in Pandas 根据其他列值更改pandas DataFrame列值 - Change a pandas DataFrame column value based on another column value 如何根据另一列的值将 pandas dataframe 的某些行添加到列表中 - How to add certain rows of a pandas dataframe to a list based on value of another column 当 pandas DataFrame 中的另一列中实现某个值时,如何编辑一列中的值? - How to edit the values in one column when a certain value is realised in another in pandas DataFrame? Python - 如何根据另一列中的值更改 pandas dataframe 的一列中的值组? - Python - How to change groups of values in one column of pandas dataframe depending on a value in another column? 如何更改 Pandas 中的 MultiIndex Dataframe 列中某些行的值 - How to change the values of certain rowns in a column of a MultiIndex Dataframe in Pandas 将 DataFrame 中某些列和行的值替换为同一 dataframe 和 Pandas 中的另一列的值 - Replace values of certain column and rows in a DataFrame with the value of another column in the same dataframe with Pandas 熊猫数据框更改列值 - pandas dataframe change column value 如何根据索引将某个值分配到 Pandas 数据框中的新列中 - How to assign a certain value into a new column in a pandas dataframe depending on index 如何检查 pandas.DataFrame 中的某个值在哪一列? - How to check in which column is certain value in pandas.DataFrame?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM