如何比较数据框中的每个元素

时间:2019-11-10 12:05:32

标签: python pandas

我想将一列中的每个元素进行比较,并在新列中打印值

在处理1个作业时,我是python面临的新问题。

这是df

package.json

我需要如下输出: 应该将“ Experience(以月为单位)”列中的每个值与min_experience列中的每个值进行比较,并在选择或拒绝的其他列中给出结果。

请帮助。

1 个答案:

答案 0 :(得分:0)

您不能尝试此操作,但我不确定这是否是您的意图。
 with cte as ( select id, convert(varchar(max), null) as name, convert(varchar(max), null) as phone, convert(varchar(max), null) as email, convert(varchar(max), names + ',') as names_rest, convert(varchar(max), phones + ',') as phones_rest, convert(varchar(max), emails + ',') as emails_rest, 0 as lev from t union all select id, left(names_rest, charindex(',', names_rest) - 1), left(phones_rest, charindex(',', phones_rest) - 1), left(emails_rest, charindex(',', emails_rest) - 1), stuff(names_rest, 1, charindex(',', names_rest), ''), stuff(phones_rest, 1, charindex(',', phones_rest), ''), stuff(emails_rest, 1, charindex(',', emails_rest), ''), lev + 1 from cte where names_rest like '%,%' ) select id, name, phone, email from cte where lev > 0;