Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
79 views
in Technique[技术] by (71.8m points)

python - How to compare between each columns text value?

I want to compare with each columns in python.

for instance :

no. name name_convert contains
0 applepie apple True
1 applepie strawberry False
2 bananashake banana True
3 bananashake banana True
question from:https://stackoverflow.com/questions/65951821/how-to-compare-between-each-columns-text-value

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can do it with list comprehension and zip function:

df['contains']=[i in j for i,j in zip(df['name_convert'],df['name'])]

: df
Out[10]: 
   no.         name name_convert  contains
0    0     applepie        apple      True
1    1     applepie   strawberry     False
2    2  bananashake       banana      True
3    3  bananashake       banana      True

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...