pandas.read_csvのusecols関数による指定カラムの読み取り
公式の解釈は以下の通りです.
usecols : list-like or callable, default None
Return a subset of the columns. If list-like, all elements must either be positional (i.e. integer indices into the document columns) or strings that correspond to column names provided either by the user in names or inferred from the document header row(s). For example, a valid list-like usecols parameter would be [0, 1, 2] or [‘foo’, ‘bar’, ‘baz’]. Element order is ignored, so
If callable, the callable function will be evaluated against the column names, returning names where the callable function evaluates to True. An example of a valid callable argument would be
よく使われる使い方はpandas.read_csv('file_name.csv',usecols=[0,1,2,3])0,1,2,3つまり前の4列を読み出し、中間の数は任意に指定できます
usecols : list-like or callable, default None
Return a subset of the columns. If list-like, all elements must either be positional (i.e. integer indices into the document columns) or strings that correspond to column names provided either by the user in names or inferred from the document header row(s). For example, a valid list-like usecols parameter would be [0, 1, 2] or [‘foo’, ‘bar’, ‘baz’]. Element order is ignored, so
usecols=[0, 1]
is the same as [1, 0]
. To instantiate a DataFrame from data
with element order preserved use pd.read_csv(data,usecols=['foo', 'bar'])[['foo', 'bar']]
for columns in ['foo', 'bar']
order or pd.read_csv(data, usecols=['foo', 'bar'])[['bar', 'foo']]
for ['bar', 'foo']
order. If callable, the callable function will be evaluated against the column names, returning names where the callable function evaluates to True. An example of a valid callable argument would be
lambda x: x.upper() in ['AAA', 'BBB', 'DDD']
. Using this parameter results in much faster parsing time and lower memory usage.’ よく使われる使い方はpandas.read_csv('file_name.csv',usecols=[0,1,2,3])0,1,2,3つまり前の4列を読み出し、中間の数は任意に指定できます