1

I used the following code to:

  1. To map the values from another data frame (Map function is used)
  2. To finalize the values in the column; where() is used

Requirement: VT_Final column to either of these values (V_Team1 or V_Team2 or Non-PA)

Issue: VT_Final returns an empty cell(blanks);

Please advise with clarifications.

Code:

Bookings['V_Team1'] = Bookings.Marker1.map(Manpower_1.set_index('Marker1')['Vertical Team'].to_dict())
Bookings['V_Team2'] = Bookings.Marker1.map(Attrition_1.set_index('Marker1')['Vertical Team'].to_dict())

Bookings['VT_Final'] = Bookings['V_Team1']
Bookings['VT_Final'].where(Bookings['V_Team1'] !='')

Bookings['VT_Final'] = Bookings['V_Team2']
Bookings['VT_Final'].where(Bookings['V_Team1'] =='')

Bookings['VT_Final'] = 'Non PA'
Bookings['VT_Final'].where((Bookings['V_Team1'] =='')&(Bookings['V_Team2']==''))
Dishin H Goyani
  • 7,195
  • 3
  • 26
  • 37
  • 1
    @Dishin H Goyani - Any suggestions? – Vishnu Varma Sep 09 '20 at 13:18
  • First i would recomand you to read the doc for [`where`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.where.html) It return values that you are not storing back to dataframe. – Dishin H Goyani Sep 09 '20 at 14:05
  • Second best solution for this would be using `numpy.select` - [this answer](https://stackoverflow.com/a/19913845/6075699) will help. – Dishin H Goyani Sep 09 '20 at 14:06

0 Answers0