Python ライブラリpandasでDataFrameを作成するサンプル
環境
Python 3.9.13
Windows 10 Home 64bit
PyCharm 2022.2.1 (Community Edition)
構文
import pandas as pd
res = pd.DataFrame({列名1:[値1,値2,…],
列名2:[値1,値2,…],
})
ライブラリpandasのDataFrameメソッドを利用してデータフレームを作成します。
使用例
import pandas as pd
# データフレーム作成
res = pd.DataFrame({
'tt': [4, 5, 6],
'ss': [71, 82, 43],
'xx': [81, 92, 53]
})
print("DataFrameを作成する結果\n")
print(res)
print("列の値を取り出す結果\n")
print(res['ss'])
実行結果
DataFrameを作成する結果 tt ss xx 0 4 71 81 1 5 82 92 2 6 43 53 列の値を取り出す結果 0 71 1 82 2 43 Name: ss, dtype: int64