数据准备 import numpy as npimport pandas as pdimport jsonimport psycopg2data = { A:[1,2,3,4,hello,world], B:[1,2,3,7,hello,word]}df_data = pd.DataFrame(data = data)df_data A B 0 11 1 22 2 33 3 47 4 hellohello 5 worldword 方法一:写函
import numpy as np import pandas as pd import json import psycopg2 data = { 'A':[1,2,3,4,'hello','world'], 'B':[1,2,3,7,'hello','word'] } df_data = pd.DataFrame(data = data) df_data
# 方法一:写函数判断 # 判断是否相等 def is_equal_or_not(a,b): if a == b: return 1 else: return 0 # 数据处理 df_data['AB列数据是否相等'] = df_data.apply(lambda x : is_equal_or_not(x['A'],x['B']),axis = 1) df_data
# 方法二:直接判断 df_data['AB列数据是否相等2'] = (df_data['A'] == df_data['B'])*1 df_data