python - assigning arrays from CSV with pandas module -
python - assigning arrays from CSV with pandas module -
if have file of 100+ columns, how can create each column array, referenced column header, without having header1 = [1,2,3], header2 = ['a','b','c'] , , on..?
here have far, headers list of header names:
import pandas pd info = [] df = pd.read_csv('outtest.csv') in headers: data.append(getattr(df, i).values)
i want each element of array headers variable name of corresponding info array in info (they in order). somehow want 1 line next line can say, example, test = headername1*headername2.
import pandas pd
if headers in csv file, can use:
df = pd.read_csv('outtest.csv')
if headers not nowadays in csv file:
headers = ['list', 'of', 'headers'] df = pd.read_csv('outtest.csv', header=none, names=headers)
assuming headername1 , headername2 constants:
test = df.headername1 * df.headername2
or
test = df['headername1'] * df['headername2']
assuming variable:
test = df[headername1] * df[headername2]
by default form of access returns pd.series
, interoperable numpy. can fetch values explicitly using .values
:
df[headername1].values
but seem know this.
python python-2.7 csv pandas
Comments
Post a Comment