あるデータの要素で変数(リスト)を分けたい場合
あるデータの要素で変数(リスト)を分けたい場合の方法です。
例として、下記のようなファイル(test.csv)を読み込み、"SAMPLE"ごとにリストに分けて格納していく方法です。今回は"SAMPLE"が1と2なので、2つに分けます。
test.csv
プログラム
test.py
import pandas as pd
#ファイル情報を読み込む
test_info=pd.read_csv("test.csv")
#SAMPLE数の最大値をサーチし格納する。今回は2。
sample_count=test_info["SAMPLE"].max()
#SAMPLEごとに格納するリストの変数宣言
sample_data=[]
#SAMPLEごとにsample_dataのリストに格納する。
for i in range(sample_count):
j=i+1
sample_data.append(test_info[test_info["SAMPLE"]==j])
結果
sample_data[0]
sample_data[1]
Author And Source
この問題について(あるデータの要素で変数(リスト)を分けたい場合), 我々は、より多くの情報をここで見つけました https://qiita.com/MAYR/items/9d38fdf36534b5efd487著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .