Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pandas does not show first column

I have a couple of function which filter a dataframe of different customers’ features and return the filtered dataframe as below:

stg_1 = strategy_1_filtering(df_1)
stg_2 = strategy_2_filtering(df_2)

Now, I make an adjacency matrix to based on Customer IDs and strategies:

d = {'stg_1':stg_1['Customer_ID'],'stg_2':stg_2['Customer_ID']}
df  = pd.DataFrame({k: dict.fromkeys(v, True) for k, v in d.items()}).fillna(False)

And the result is something like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

stg_1 stg_2
385986.0 True True
363015.0 True False
411847.0 True True
413369.0 True True
401081.0 True False

I have tried to change the name of first column using this code:

 df.columns.values[0] = "Customer_ID"

But it did not work. To understand the problem I printed shape and column names of the dataframe:

print(df.shape)
print(df.columns)

The results:

(1155, 2)
Index(['stg_1', 'stg_2'], dtype='object')

In this case, when the dataframe cannot detect even the first column, what should I do?

>Solution :

I assume your first column is actually the index of the DataFrame.
To name it:

df.index.name = "Customer_ID"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading