3

This might be a silly question to ask, however, it is for a specific task in a multi-step process to clean up some data.

Basically, each column label is a location represented as a series of long numbers. Each column contains measurement values in each subsequent row for those locations. I do not need the measurements, only the locations (hence why I just need the column labels only).

The reason I need this is because I need to replace some mixed up column labels in one CSV file with the correct column labels from another CSV file.

I cannot do this in Excel since there are too many columns to read in (over 300,000 columns). I am essentially looking for a way to do a coded "Copy" and "Paste" from one file to another using Pandas if it can be done.

I had a considered just dropping the columns I do not need, however, because the columns are labelled as numbers, I'd be filtering based on a multiple set of a conditions. I thought this method would be easier.

Thank you for your help.

2 Answers2

1

If you want to see only columns you may use:

df.columns

Also, to change it - just use:

df.columns = ['column_name_1', 'column_name_2', ... ,'column_name_n']

As you understand, using same logic you can do anything, such as map function to column names.

Stas Buzuluk
  • 794
  • 9
  • 19
1

Just dodataframe.columns to get all column names

Irfan Umar
  • 196
  • 3
  • 18