##list(df_b.columns[~df_b.columns.isin(["val4","val5"]) ]) でval4,val5以外の全ての列を選択出来ます。
#テストデータ
import pandas as pd
a={"idx" :[10,20,30],
"val1":[11,12,13]}
b={"idx" :[10,20,30],
"val2":[21,22,23],
"val3":[31,32,33],
"val4":[41,42,43],
"val5":[51,52,53],
}
df_a=pd.DataFrame(a)
df_a.set_index(["idx"],inplace=True)
df_b=pd.DataFrame(b)
df_b.set_index(["idx"],inplace=True)
print(df_a.to_markdown())
print(df_b.to_markdown())
df_a
idx | val1 |
---|---|
10 | 11 |
20 | 12 |
30 | 13 |
df_b
idx | val2 | val3 | val4 | val5 |
---|---|---|---|---|
10 | 21 | 31 | 41 | 51 |
20 | 22 | 32 | 42 | 52 |
30 | 23 | 33 | 43 | 53 |
#コピー(val4、Va15以外)
cols=list(df_b.columns[~df_b.columns.isin(["val4","val5"]) ])
df_a[cols]=df_b[cols]
print(df_a.to_markdown())
df_a
idx | val1 | val2 | val3 |
---|---|---|---|
10 | 11 | 21 | 31 |
20 | 12 | 22 | 32 |
30 | 13 | 23 | 33 |