回答編集履歴

2

修正

2020/12/08 13:18

投稿

tiitoi
tiitoi

スコア21960

test CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
 
20
20
 
21
- df10 = pd.DataFrame(
21
+ df1 = pd.DataFrame(
22
22
 
23
23
  [
24
24
 
@@ -38,7 +38,7 @@
38
38
 
39
39
 
40
40
 
41
- df12 = pd.DataFrame(
41
+ df2 = pd.DataFrame(
42
42
 
43
43
  [[3320, "電気"], [6701, "石油"], [4536, "通信"], [7777,]], columns=["番号", "業種"]
44
44
 
@@ -46,7 +46,9 @@
46
46
 
47
47
 
48
48
 
49
- merged = pd.merge(df10, df12, on="番号", suffixes=("", "_y"))
49
+ merged = pd.merge(df1, df2, on="番号", suffixes=("", "_y"))
50
+
51
+ merged["業種"].update(merged["業種_y"])
50
52
 
51
53
 
52
54
 

1

d

2020/12/08 13:18

投稿

tiitoi
tiitoi

スコア21960

test CHANGED
@@ -1,4 +1,4 @@
1
- 列名が重複した場合、左側の列を残すとして
1
+ 列名が重複した場合、左側の DataFrame の列を残すとして
2
2
 
3
3
 
4
4
 
@@ -57,3 +57,17 @@
57
57
  print(merged)
58
58
 
59
59
  ```
60
+
61
+
62
+
63
+ > suffixeslist-like, default is (“_x”, “_y”)
64
+
65
+ A length-2 sequence where each element is optionally a string indicating the suffix to add to overlapping column names in left and right respectively. Pass a value of None instead of a string to indicate that the column name from left or right should be left as-is, with no suffix. At least one of the values must not be None.
66
+
67
+
68
+
69
+ * [pandas.DataFrame.merge — pandas 1.1.4 documentation](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.merge.html)
70
+
71
+
72
+
73
+ * [pandas - DataFrame を結合する pandas.merge の使い方 ](https://pystyle.info/pandas-merge/#outline__2_4)