-1

Dataframe sample

Keep in mind the 'None' value is a string so can't use .fillna

df[df['TRIPLINE'] == 'None']

I want to fill these string values with the corresponding value in the 'LINE' column

3 Answers3

0

As long as None is truly a string and not a np.nan or None you can use np.where()

import numpy as np
df['TRIPLINE'] = np.where(df['TRIPLINE'] == 'None', df['LINE'], df['TRIPLINE'])
ArchAngelPwn
  • 2,891
  • 1
  • 4
  • 17
0

Use .loc with your == 'None' mask:

act_thruput_raw.loc[act_thruput_raw['TRIPLINE'] == 'None', 'TRIPLINE'] = act_thruput_raw['LINE']
0

IIUC,

df['TRIPLINE'] = df['TRIPLINE'].mask(df['TRIPLINE'] == 'None', df['LINE'])
Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52