简体   繁体   English

根据另一列中的“NaN”值在 Pandas Dataframe 中创建一个新列

[英]Create a new column in Pandas Dataframe based on the 'NaN' values in another column

I have a dataframe:我有一个数据框:

A B
1 NaN
2 3
4 NaN
5 NaN
6 7

Yes, it's simple.是的,这很简单。 Use pandas.Series.where<\/code><\/a> :使用pandas.Series.where<\/code><\/a> :

df['C'] = df['A'].where(df['B'].isna(), df['B'])

暂无
暂无

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

相关问题 根据其他列中的“NaN”值在 Pandas Dataframe 中创建一个新列 - Create a new column in Pandas Dataframe based on the 'NaN' values in other columns 如何基于另一列的NaN值设置熊猫数据框中的值? - How set values in pandas dataframe based on NaN values of another column? Pandas 基于另一个 dataframe 将多个列和行值设置为 nan - Pandas Set multiple column and row values to nan based on another dataframe 根据另一列中的 NaN 值创建新列 - Create a new column based on NaN values in another column 如何基于另一个DataFrame中的列在Pandas DataFrame中创建新列? - How to create a new column in a Pandas DataFrame based on a column in another DataFrame? 基于其他两个包含 NaN 值的列在 pandas DataFrame 中创建一个新列 - create a new column in pandas DataFrame based on two others which contain NaN values 如何基于另一列的值在pandas dataframe列中创建新值 - How to create new values in a pandas dataframe column based on values from another column 如何根据 Python Pandas 中 DataFrame 中的另一列中的值创建具有隔间的新列? - How to create a new column with compartments based on values in another column in DataFrame in Python Pandas? 熊猫:在一个数据框中创建新列,并根据与另一个数据框中的匹配键进行匹配 - Pandas: create new column in one dataframe with values based on matching key from another dataframe 根据数据框中另一列的值创建一个新列 - Create a new column based on the values of another column in a dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM