回答編集履歴

1

d

2020/05/22 09:35

投稿

tiitoi
tiitoi

スコア21956

test CHANGED
@@ -75,3 +75,63 @@
75
75
  # 2 102 202 302
76
76
 
77
77
  ```
78
+
79
+
80
+
81
+ ## 追記
82
+
83
+
84
+
85
+ 考えられる可能性として、`index` という列名が DataFrame のインデックスになっていない可能性があります。その場合、set_index() でインデックスに設定できます。
86
+
87
+
88
+
89
+ ```python
90
+
91
+ import pandas as pd
92
+
93
+
94
+
95
+
96
+
97
+ df = pd.DataFrame(
98
+
99
+ [
100
+
101
+ [1, 101, 201, 301],
102
+
103
+ [2, 102, 202, 302],
104
+
105
+ [3, 103, 203, 303],
106
+
107
+ [4, 104, 204, 304],
108
+
109
+ [5, 105, 205, 305],
110
+
111
+ ],
112
+
113
+ columns=["index", 1, 2, 3]
114
+
115
+ )
116
+
117
+ print(df)
118
+
119
+ # index 1 2 3
120
+
121
+ # 0 1 101 201 301
122
+
123
+ # 1 2 102 202 302
124
+
125
+ # 2 3 103 203 303
126
+
127
+ # 3 4 104 204 304
128
+
129
+ # 4 5 105 205 305
130
+
131
+
132
+
133
+ df = df.set_index("index")
134
+
135
+ print(df.loc[2])
136
+
137
+ ```