回答編集履歴
1
コード修正
test
CHANGED
@@ -44,33 +44,21 @@
|
|
44
44
|
|
45
45
|
|
46
46
|
|
47
|
-
#
|
47
|
+
# Seriesに展開
|
48
48
|
|
49
|
-
|
49
|
+
series = {}
|
50
50
|
|
51
|
-
|
51
|
+
for key in ['name', 'price']:
|
52
|
+
|
53
|
+
f = lambda row: to_sr(row['info'], key)
|
54
|
+
|
55
|
+
series[key] = df.apply(f, axis=1).stack().reset_index(level=1, drop=True)
|
52
56
|
|
53
57
|
|
54
58
|
|
55
|
-
# a
|
59
|
+
# 各SeriesをDataFrameに結合し元dfに結合
|
56
60
|
|
57
|
-
def f_price(row):
|
58
|
-
|
59
|
-
return to_sr(row['info'], 'price')
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
# Seriesに展開
|
64
|
-
|
65
|
-
s_n = df.apply(f_name, axis=1).stack().reset_index(level=1, drop=True)
|
66
|
-
|
67
|
-
s_p = df.apply(f_price, axis=1).stack().reset_index(level=1, drop=True)
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
# 元dfに結合
|
72
|
-
|
73
|
-
dfs = pd.DataFrame(
|
61
|
+
dfs = pd.DataFrame(series)
|
74
62
|
|
75
63
|
df = df.drop('info', axis=1).join(dfs).reset_index(drop=True)
|
76
64
|
|