how to pandas fast nested for loop for "non numeric" columns? because this for loop is way to slow:
for i in range(len(df1[column_A]):
for j in range(len(df2[column_A]):
if df1[column_A][i] == df2[column_A][j]:
df1[column_B][i] = df2[column_B][j]
else:
pass
so any other way to do it by pandas itself or other libraries?
UPDATE:
and main goal is:
input:
df1:
name rpm power
0 John 1500 high+
1 Mary 1400 high-
2 Sally 300 low-
3 Doe 700 medium-
4 July 1000 medium+
df2:
name age
0 Peter 77
1 Sally 44
2 Micky 22
3 Sally 34
4 July 50
5 Bob 20
required output is:
but i want it df2:
name age rpm power
0 Peter 77 0 NA
1 Sally 44 300 low-
2 Micky 22 0 NA
3 Sally 34 300 low-
4 July 50 1000 medium+
5 Bob 20 0 NA
i also add question in official pandas github: https://github.com/pandas-dev/pandas/issues/59824