After stacking a file, the header row is empty i.e. no column names. Whatever I've tried has not yielded any change to that.
Thanks.
P.S. Is it possible to stack select columns from a csv, and not all columns that are not an index?
First line of idx_input.csv is a data row, not a column header. Are any of what I've tried valid? I'm simply trying to stack with column names preserved. What I do in JMP I'd like to do in Pandas.
data_file = pd.read_csv(filename)
idx_input = data_file.set_index(default_stack_group).stack()
default_stack_group = ['X','Y']
cols = default_stack_group + ['Label','Data']
#Option 1 I tried
#idx_input.reset_index().rename(columns{0:cols[0],1:cols[1],2:cols[2],3:cols[3]})
#Option 2 I tried
#idx_input.reset_index()
#idx_input.rename(columns=0:cols[0],1:cols[1],2:cols[2],3:cols[3]},inplace=True)
#Option 3 I tried
#idx_input.columns = cols
idx_input.to_csv('idx_input.csv')
No error message observed (besides a warning)
trial_crunch.py:38: FutureWarning: The signature of Series.to_csv
was aligned
to that of DataFrame.to_csv
, and argument 'header' will change its default val
ue from False to True: please pass an explicit value to suppress this warning.
idx_input.to_csv('idx_input2.csv')
My first row is already a data column and not a header column. The data is stacked.