回答編集履歴

1

修正

2020/08/29 01:36

投稿

8524ba23
8524ba23

スコア38341

test CHANGED
@@ -1,4 +1,76 @@
1
1
  欲しい結果は以下のようなものでしょうか。
2
+
3
+
4
+
5
+ ```Python
6
+
7
+ import pandas as pd
8
+
9
+
10
+
11
+ df1 = pd.DataFrame({'Date1':['2019-01-01','2019-01-02','2019-01-03'], 'value1':[1,2,3]})
12
+
13
+ df2 = pd.DataFrame({'Date2':['2019-01-01','2019-01-03'], 'value2':[10,30]})
14
+
15
+ df1['Date1'] = pd.to_datetime(df1['Date1'])
16
+
17
+ df2['Date2'] = pd.to_datetime(df2['Date2'])
18
+
19
+ print(df1)
20
+
21
+ # Date1 value1
22
+
23
+ #0 2019-01-01 1
24
+
25
+ #1 2019-01-02 2
26
+
27
+ #2 2019-01-03 3
28
+
29
+ print(df2)
30
+
31
+ # Date2 value2
32
+
33
+ #0 2019-01-01 10
34
+
35
+ #1 2019-01-03 30
36
+
37
+
38
+
39
+ # 両方に存在する日付のみ抽出
40
+
41
+ s = set(df1['Date1']) & set(df2['Date2'])
42
+
43
+
44
+
45
+ df1 = df1[df1['Date1'].isin(s)]
46
+
47
+ print(df1)
48
+
49
+ # Date1 value1
50
+
51
+ #0 2019-01-01 1
52
+
53
+ #2 2019-01-03 3
54
+
55
+
56
+
57
+ df2 = df2[df2['Date2'].isin(s)]
58
+
59
+ print(df2)
60
+
61
+ # Date2 value2
62
+
63
+ #0 2019-01-01 10
64
+
65
+ #1 2019-01-03 30
66
+
67
+ ```
68
+
69
+
70
+
71
+ 質問修正前の回答
72
+
73
+ -----
2
74
 
3
75
  ```Python
4
76