I have two Dataframes of identical Size. For simplicity's sake
df1 =
start n end
0 20200712 50000 20200812
1 20200714 51000 20200814
2 20200716 51500 20200816
3 20200719 53000 20200819
4 20200721 54000 20200821
5 20200724 55000 20200824
6 20200729 57000 20200824
df2 =
start n end
0 20200712 0 20200812
1 20200714 15 20200814
2 20200716 51500 20200816
3 20200719 53000 20200819
4 20200721 30 20200821
5 20200724 55000 20200824
6 20200729 57000 20200824
I would like to replace all 'n's in df2 with those in df1 when a condition is met(here n <50)
I have something like this in mind, which works.
df2.loc[df2['n']<50,'n'] = df1['n']
to get
start n end
0 20200712 50000 20200812
1 20200714 51000 20200814
2 20200716 51500 20200816
3 20200719 53000 20200819
4 20200721 54000 20200821
5 20200724 55000 20200824
6 20200729 57000 20200824
What is the most efficient or 'proper' way when i have multiple such 'n'columns?