iloc[1]で行の結果のみが出力されるのであれば、なぜ結果が列で表示されるのでしょうか?
Scalar 値を指定すると pandas.core.series.Series
型のインスタンスが返り、リスト(sequence型)を指定すると pandas.core.frame.DataFrame
型のインスタンスが返ります。
python
1>>> import pandas as pd
2>>> help(pd.DataFrame.iloc)
3
4 :
5
6 Examples
7 --------
8 >>> mydict = [{'a': 1, 'b': 2, 'c': 3, 'd': 4},
9 ... {'a': 100, 'b': 200, 'c': 300, 'd': 400},
10 ... {'a': 1000, 'b': 2000, 'c': 3000, 'd': 4000 }]
11 >>> df = pd.DataFrame(mydict)
12 >>> df
13 a b c d
14 0 1 2 3 4
15 1 100 200 300 400
16 2 1000 2000 3000 4000
17
18 **Indexing just the rows**
19
20 With a scalar integer.
21
22 >>> type(df.iloc[0])
23 <class 'pandas.core.series.Series'>
24 >>> df.iloc[0]
25 a 1
26 b 2
27 c 3
28 d 4
29 Name: 0, dtype: int64
30
31 With a list of integers.
32
33 >>> df.iloc[[0]]
34 a b c d
35 0 1 2 3 4
36 >>> type(df.iloc[[0]])
37 <class 'pandas.core.frame.DataFrame'>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/04/30 00:55