Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to select only column labels using Pyhon Pandas library without any rows? [duplicate]

Tags:

python

pandas

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.

like image 793
some_name_some_numbers Avatar asked Nov 18 '25 13:11

some_name_some_numbers


1 Answers

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.

like image 166
Stas Buzuluk Avatar answered Nov 20 '25 03:11

Stas Buzuluk