Col0 Col1 Col2
2015 1 4
2016 2 3
の形式のデータファイルのデータがfloatである、と私はndarray
を作るためにnumpty
loadtext
を使用しています。しかし、データの配列を持つために、ラベルの行と列をスキップする必要があります。ラベルを読み取っているときに、データのうちndarray
をどのようにして消してしまえますか?
import numpy as np
import matplotlib.pyplot as plt
data = np.loadtxt("data.csv", skiprows=1)
# I need to skip the first row in reading the data but still get the labels.
x= data[:,0]
a= data[:,1]
b= data[:,2]
plt.xlabel(COL0) # Reading the COL0 value from the file.
plt.ylabel(COL1) # Reading the COL1 value from the file.
plt.plot(x,a)
注:ラベル(列タイトルは)スクリプトで不明です。このスクリプトは、同じ構造の入力ファイルで動作するように汎用的でなければなりません。
通常の人々がこのようなタスクのためのパンダを使用しています。 'df = pandas.read_csv()'は、 'df.columns'でアクセス可能なカラム名を持つように、名前付きカラムを持つデータフレームを与えます。 – ImportanceOfBeingErnest