0

I want to compare each element from one column to other and print value in new column

I am new in python facing problem while working on 1 assignment.

Here is the df

Index  |  min_experience  |  Experience (in months)
0      |      12.0        |      36
1      |      24.0        |      10
2      |      60.0        |      65
3      |      0.0         |      55
4      |      36.0        |      20
5      |      84.0        |      28
6      |      120.0       |      24
7      |      0.0         |      0
8      |      0.0         |      28

I need output like: each value in Column "Experience (in months)" should be compared with every value in column min_experience and give result in other column as selected or rejected.

Please help.

edgarzamora
  • 1,472
  • 1
  • 9
  • 17
  • Did you try any implementation before post the question? Can you share what you tried with us? Are you using pandas library? When you talk about comparing the columns, can you specify how you want them to compare (less than, equals, ...) – edgarzamora Nov 10 '19 at 12:19
  • Hi, i am using pandas and numpy library. i have used this code earlier. But it is comparing next value to it. I want each value to be compared as equal to or greater than. np.where(New_data['min_experience']>=New_data['Experience (in months)'], 'selected', 'Rejected') – Swapnil Dagar Nov 10 '19 at 12:25
  • Search this site for "pandas add a new column." This one will give you the general idea: https://stackoverflow.com/questions/12555323/adding-new-column-to-existing-dataframe-in-python-pandas/12555510#12555510 . This is using a simple calculation (however, you would want to perhaps have a boolean instead of a numerical result): https://stackoverflow.com/questions/40222181/pandas-dataframe-create-new-column-based-on-simple-calcuation – rajah9 Nov 10 '19 at 12:36

1 Answers1

0

You cant try this i am not sure if this is your intention though.
df['status'] = (df['min_experience']<=df['Experience(in_months)').apply(lambda x:'selected' if x else 'unselected')

Gary Ong
  • 788
  • 1
  • 5
  • 8