回答編集履歴
4
Update
test
CHANGED
@@ -78,7 +78,7 @@
|
|
78
78
|
|
79
79
|
df_list = []
|
80
80
|
|
81
|
-
for
|
81
|
+
for s in soup_html:
|
82
82
|
|
83
83
|
rank_list = []
|
84
84
|
|
@@ -90,7 +90,7 @@
|
|
90
90
|
|
91
91
|
|
92
92
|
|
93
|
-
content =
|
93
|
+
content = s.find_all(class_='Num')
|
94
94
|
|
95
95
|
for i in content:
|
96
96
|
|
@@ -104,7 +104,7 @@
|
|
104
104
|
|
105
105
|
|
106
106
|
|
107
|
-
content =
|
107
|
+
content = s.find_all(class_='height')
|
108
108
|
|
109
109
|
for i in content:
|
110
110
|
|
@@ -118,7 +118,7 @@
|
|
118
118
|
|
119
119
|
|
120
120
|
|
121
|
-
content =
|
121
|
+
content = s.find_all(class_='weight')
|
122
122
|
|
123
123
|
for i in content:
|
124
124
|
|
3
Update
test
CHANGED
@@ -68,40 +68,78 @@
|
|
68
68
|
|
69
69
|
|
70
70
|
|
71
|
-
>
|
71
|
+
> 以下が現在のコードでどのように変更すれば、実現できるのか
|
72
72
|
|
73
73
|
|
74
74
|
|
75
|
-
以下の
|
75
|
+
以下、かなり冗長ですが書き換えの一例として参考にして下さい(動作保証はありません)。
|
76
76
|
|
77
77
|
```python
|
78
78
|
|
79
79
|
df_list = []
|
80
80
|
|
81
|
-
for i in soup:
|
81
|
+
for i in soup_html:
|
82
82
|
|
83
|
-
|
83
|
+
rank_list = []
|
84
84
|
|
85
|
+
height_list = []
|
86
|
+
|
85
|
-
|
87
|
+
weight = []
|
88
|
+
|
89
|
+
df = pd.DataFrame()
|
86
90
|
|
87
91
|
|
88
92
|
|
93
|
+
content = i.find_all(class_='Num')
|
94
|
+
|
95
|
+
for i in content:
|
96
|
+
|
97
|
+
rank = i.text
|
98
|
+
|
99
|
+
rank = rank.replace('\n', '')
|
100
|
+
|
89
|
-
|
101
|
+
rank_list.append(rank)
|
90
102
|
|
91
103
|
df['成績'] = rank_list
|
92
104
|
|
105
|
+
|
106
|
+
|
107
|
+
content = i.find_all(class_='height')
|
108
|
+
|
93
|
-
|
109
|
+
for i in content:
|
110
|
+
|
111
|
+
height = i.text
|
112
|
+
|
113
|
+
height = height.replace('\n', '')
|
114
|
+
|
115
|
+
height_list.append(height)
|
116
|
+
|
117
|
+
df['身長'] = height_list
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
content = i.find_all(class_='weight')
|
122
|
+
|
123
|
+
for i in content:
|
124
|
+
|
125
|
+
weight = i.text
|
126
|
+
|
127
|
+
weight = weight.replace('\n', '')
|
128
|
+
|
129
|
+
weight_list.append(weight)
|
130
|
+
|
131
|
+
df['体重'] = weight_list
|
94
132
|
|
95
133
|
|
96
134
|
|
97
135
|
# for i in soup のループが1回完了する毎にリストに追加します
|
98
136
|
|
99
|
-
df_list.append(df)
|
137
|
+
df_list.append(df.sort_values('成績'))
|
100
138
|
|
101
139
|
|
102
140
|
|
103
141
|
# 全て取得したら縦に連結
|
104
142
|
|
105
|
-
df_all = pd.concat(
|
143
|
+
df_all = pd.concat(df_list)
|
106
144
|
|
107
145
|
```
|
2
Update
test
CHANGED
@@ -61,3 +61,47 @@
|
|
61
61
|
B 168 58 3 2
|
62
62
|
|
63
63
|
```
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
**追記**
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
> 上記のような手法でDFを作成しています。
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
以下の様な流れになるかと思います。
|
76
|
+
|
77
|
+
```python
|
78
|
+
|
79
|
+
df_list = []
|
80
|
+
|
81
|
+
for i in soup: # soupを取得(ここが1000個近くある部分)
|
82
|
+
|
83
|
+
for i in content: # 成績、身長、体重を取得
|
84
|
+
|
85
|
+
:
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
df = pd.DataFrame()
|
90
|
+
|
91
|
+
df['成績'] = rank_list
|
92
|
+
|
93
|
+
:
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
# for i in soup のループが1回完了する毎にリストに追加します
|
98
|
+
|
99
|
+
df_list.append(df)
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
# 全て取得したら縦に連結
|
104
|
+
|
105
|
+
df_all = pd.concat(i.sort_values('成績') for i in df_list)
|
106
|
+
|
107
|
+
```
|
1
Update
test
CHANGED
@@ -38,13 +38,11 @@
|
|
38
38
|
|
39
39
|
|
40
40
|
|
41
|
-
df3 = pd.concat(
|
41
|
+
df3 = pd.concat(i.sort_values('成績') for i in (df1, df2))
|
42
42
|
|
43
43
|
|
44
44
|
|
45
45
|
print(df3)
|
46
|
-
|
47
|
-
|
48
46
|
|
49
47
|
#
|
50
48
|
|