I use pandas dataframe to plot csv. data taken with a spectrometer.
df = pd.read_csv("C:\\file.csv") # import file
The output table always consists of pairs
| sample 1 | Unnamed:1 | sample 2 | Unnamed:2 | ... |
|---|---|---|---|---|
| wavelengths | transmission 1 | wavelengths | transmission 2 | ... |
One column belonging to each sample ('sample 1', 'sample 2',...) where relevant information about the samples is stored in the header, but the column is only containing the wavelength information
One numbered column ('Unnamed: 1', 'Unnamed: 2',...) that actually contains the relevant measured information
I would now like to display the data as a function of the wavelength. If I delete all columns containing the redundant wavelength information by using
df = df.drop(data.columns[1,37], axis=1, inplace=False)
I lose the information about the samples contained in the heading I am now thinking about swapping the column headings and then deleting the columns I don't need. I could of course swap the columns by name using something
df[['sample 1','Unnamed: 1']]=df[['Unnamed: 1','sample 1']]
but then I would have to enter the names for each new data series that sometimes contain more than 10 paired columns.
Is there a way to swap the headings via index? Or can you think of a more elegant version? This form of tabular data output, where the header always spans two columns, is certainly not an isolated case. Thanks a lot