「Python」pandasのtolistメソッドでシリーズをリストに変換するサンプル

環境

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
pandas 1.4.2
PyCharm 2021.3.3
pandas 1.4.2 PyCharm 2021.3.3
pandas 1.4.2
PyCharm 2021.3.3

構文
1.Series.mode(dropna=True)
シリーズのモードを返します。
モードは、最も頻繁に表示される値です。 複数のモードがあります。
値が1つだけ返される場合でも、常にSeriesを返します。

パラメーター
dropnabool、デフォルトはTrue
NaN/NaTの数を考慮しないでください。

戻り値 シリーズ
ソートされた順序でのシリーズのモード。
pandas.Seriesからmode()を呼ぶとpandas.Seriesが返ります

2.mode().tolist()
シリーズからリストへ変換します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
import pandas as pd
cft = pd.Series([21, 32, 43, 54, 65])
print(cft)
resList = cft.tolist()
print("シリーズからリストへ変換する結果")
print(resList)
# coding: utf-8 import pandas as pd cft = pd.Series([21, 32, 43, 54, 65]) print(cft) resList = cft.tolist() print("シリーズからリストへ変換する結果") print(resList)
# coding: utf-8
import pandas as pd
cft = pd.Series([21, 32, 43, 54, 65])
print(cft)

resList = cft.tolist()
print("シリーズからリストへ変換する結果")
print(resList)

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
0 21
1 32
2 43
3 54
4 65
dtype: int64
シリーズからリストへ変換する結果
[21, 32, 43, 54, 65]
0 21 1 32 2 43 3 54 4 65 dtype: int64 シリーズからリストへ変換する結果 [21, 32, 43, 54, 65]
0    21
1    32
2    43
3    54
4    65
dtype: int64
シリーズからリストへ変換する結果
[21, 32, 43, 54, 65]

 

Python

Posted by arkgame