Pandas Columns From Another Dataframe If Value Is In Another Column?
I have pd.DataFrame listing wire gauges and their corresponding currents: e_ref = wire_gauge current 0 14 15 1 12 20 2 10 30 3
Solution 1:
Use map
by Series
created form e_ref
or join
, but is necessary values in current
column in e_ref
has to be unique:
print (e_ref['current'].is_unique)
True
s = e_ref.set_index('current')['wire_gauge']
system['wire_gauge'] = system['breakers'].map(s)
print (system)
breakers wire_gauge
0301012012230103151443010
Alternative:
df = system.join(e_ref.set_index('current'), on='breakers')
print (df)
breakers wire_gauge
0 30 10
1 20 12
2 30 10
3 15 14
4 30 10
Post a Comment for "Pandas Columns From Another Dataframe If Value Is In Another Column?"