以下のようなテキスト ファイル (data.txt) があります。
name height weight
A 15.5 55.7
B 18.9 51.6
C 17.4 67.3
D 11.4 34.5
E 23.4 92.1
パンダを使用して各列のリストをPythonで作成したい。
import pandas
with open (pandas.read_csv('data.txt')) as df:
name= df.icol(0)
height= df.icol(1)
weight= df.icol(2)
print (name)
print (height)
print (weight)
また、リストからヘッダー (名前、身長、体重) を避けたいと考えています。
print (df) は次のように提供します。
name\theight\tweight
0 A\t15.5\t55.7
1 B\t18.9\t51.6
2 C\t17.4\t67.3
3 D\t11.4\t34.5
4 E\t23.4\t92.1