回答編集履歴

1

Update

2022/06/05 12:19

投稿

melian
melian

スコア19838

test CHANGED
@@ -1,16 +1,15 @@
1
1
  ```python
2
- dfx = pd.concat([df1, df2])
3
- dfx = dfx[dfx['contents_id'].isin(df2['contents_id'])].sort_values('contents_id')
2
+ dfx = pd.concat([df1, df2]).query('contents_id in @df2["contents_id"]').sort_values('contents_id')
4
3
  print(dfx.to_markdown(index=False))
5
4
  ```
6
5
 
7
- | user_id | contents_id | rating |
6
+ | user_id | contents_id | rating |
8
- |----------:|--------------:|---------:|
7
+ |----------:|--------------:|:---------|
9
- | 1 | 11 | 3 |
8
+ | 1 | 11 | 3 |
10
- | 3 | 11 | 4 |
9
+ | 3 | 11 | 4 |
11
- | 5 | 11 | nan |
10
+ | 5 | 11 | |
12
- | 2 | 12 | 3 |
11
+ | 2 | 12 | 3 |
13
- | 5 | 12 | nan |
12
+ | 5 | 12 | |
14
- | 3 | 13 | 4 |
13
+ | 3 | 13 | 4 |
15
- | 5 | 13 | nan |
14
+ | 5 | 13 | |
16
15