0

This is my dataset

    0           1           2
0   1.000000    0.063373    0.753792
1   0.063373    1.000000    0.031112
2   0.753792    0.031112    1.000000

When I do similarity_df.columns the answer is RangeIndex(start=0, stop=3, step=1) what I want is Index(['0', '1', '2'], dtype='object') and what I did is

df.columns = ['0', '1', '2']

The actual data is more than 2000 columns, and I need to select several column, how to make the code efficiently

Nabih Bawazir
  • 6,381
  • 7
  • 37
  • 70
  • 3
    I think it is dupe, `df.columns = df.columns.astype(str)` – jezrael Apr 24 '18 at 09:22
  • 1
    if you want to change column name you can do that by `df.rename(columns={0:"Column0", 1:"Column1",2:"Column2",3:"Column2"}) df.head() ` By assigning each column proper name will help you in your analysis. Now as you mention that you have 2000 columns so you can have loop to name all your columns . This will make your analysis easy when dealing with a lot of columns Now if you want to change its type to str so you can do that by `column0=df['column0'].astype(str)` – fahad pirzada Apr 24 '18 at 09:36

0 Answers0