简体   繁体   English

如果两列值相等,则在 Python 中创建具有 True 和 False 值的第三列

[英]if two column values are equal then create 3rd column which has True and False values in Python

I want to get 3rd column which would have boolean values ie True and False, say I have column A which has numeric value and column B which also has some numeric value, I need to compare them whether they're equal, so If they're equal then there will be TRUE value in 3rd column, else False in python data frame我想获得具有 boolean 值的第 3 列,即 True 和 False,假设我有 A 列有数值,B 列也有一些数值,我需要比较它们是否相等,所以如果他们重新相等,则第 3 列中的值为 TRUE,否则 python 数据帧中的值为 False

Input:输入:

在此处输入图像描述

Output Required Output 需要

在此处输入图像描述

df['3rd Column']=df['A']==df['B']

df:

  A    B    Third Column
 10    20   FALSE
 20    10   FALSE
 30    30   TRUE
 50    40   FALSE
 80    60   FALSE`

暂无
暂无

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

相关问题 xyzc值数组,找出第三列是否有c值等于1或不为零的行 - Array of xyzc values , Find out if 3rd column has any rows with c value equal to 1, or not zero 根据两列值在 Python DataFrame(1,0) 中创建 True/False 列 - Create a True/False column in Python DataFrame(1,0) based on two columns values 熊猫按两列分组,并从第三列输出值 - Pandas groupby two columns and output values from 3rd column 扫描多列值以创建具有真值或假值的新列 - Scanning Multiple Column values to create new Column with True or False Value Python - 创建一列等于另一列的值,但如果第一列中出现两个连续值,则使新列等于 0 - Python - Create a column equal to the value of another column but if two consecutive values occur in the first column then make new column equal to 0 Pandas:如果来自第三列的字符串值,则根据另一列的值创建列 - Pandas : Create columns based on values of another column if string value from 3rd column 使用 True/False 将列值移动到值 - Move column values to values with True/False Python 比较 2 列并用第 3 列中的值写入第 4 列(熊猫) - Python Compare 2 Columns And Write A 4th Column With Values From 3rd Column (pandas ) pandas 使用值中的名称创建列并替换为 True/False - pandas create column with names from values and substitute with True/False 用 True 和 False 替换“qualify”列值“yes”和“no”的 Python 程序 - Python program to replace the 'qualify' column values 'yes' and 'no' with True and False
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM