回答編集履歴
3
ふりがなを付けた例を追記
test
CHANGED
@@ -107,3 +107,45 @@
|
|
107
107
|
ret = ret.sort_values('名前', ignore_index=True)
|
108
108
|
|
109
109
|
```
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
---
|
114
|
+
|
115
|
+
【ふりがなを付けた例】
|
116
|
+
|
117
|
+
```Python
|
118
|
+
|
119
|
+
import pandas as pd
|
120
|
+
|
121
|
+
from pandas import DataFrame,Series
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
#score
|
126
|
+
|
127
|
+
data={
|
128
|
+
|
129
|
+
"名前":["浅田","今川","宇佐","江田","小野","加納","岸辺","倉田","剣持"],
|
130
|
+
|
131
|
+
"ふりがな":["あさだ","いまがわ","うさ","えだ","おの","かのう","きしべ","くらた","けんもち"],
|
132
|
+
|
133
|
+
"こくご":["79","75","49","99","96","94","48","21","88"],
|
134
|
+
|
135
|
+
"さんすう":["3","70","89","47","29","88","17","67","8"],
|
136
|
+
|
137
|
+
"えいご":["33","22","65","5","36","45","19","100","36"]
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
#データフレームscore
|
144
|
+
|
145
|
+
score = DataFrame(data)
|
146
|
+
|
147
|
+
ret = score.melt(id_vars=['名前','ふりがな'], var_name='科目名', value_name='点数').sort_values('ふりがな', ignore_index=True)
|
148
|
+
|
149
|
+
print(ret)
|
150
|
+
|
151
|
+
```
|
2
使ってるの pandas.melt() じゃなくて DataFrame.melt() だった・・
test
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
`pandas.melt()`をお使い下さい
|
1
|
+
`pandas.DataFrame.melt()`をお使い下さい
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
[https://pandas.pydata.org/docs/reference/api/pandas.melt.html](https://pandas.pydata.org/docs/reference/api/pandas.melt.html)
|
5
|
+
[https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.melt.html#pandas.DataFrame.melt](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.melt.html#pandas.DataFrame.melt)
|
6
|
-
|
7
|
-
|
8
6
|
|
9
7
|
```Python
|
10
8
|
|
1
説明追加
test
CHANGED
@@ -95,3 +95,17 @@
|
|
95
95
|
#26 剣持 えいご 36
|
96
96
|
|
97
97
|
```
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
更に、出力を名前順にしたい場合は、`DataFrame.sort_values()` でソートします。
|
102
|
+
|
103
|
+
[https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.sort_values.html
|
104
|
+
|
105
|
+
](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.sort_values.html)
|
106
|
+
|
107
|
+
```Python
|
108
|
+
|
109
|
+
ret = ret.sort_values('名前', ignore_index=True)
|
110
|
+
|
111
|
+
```
|