0

The dataframe below has a number of columns but columns names are random numbers.

daily1=

 0 1 2 3 4 5 6 7 8 9 ... 11 12 13 14 15 16 17 18 19 20 0 0 0 0 0 0 0 4 0 0 0 ... 640 777 674 842 786 865 809 674 679 852 1 0 0 0 0 0 0 0 0 0 0 ... 108 29 74 102 82 62 83 68 30 61 2 rows × 244 columns 

I would like to organise columns names in numerical order(from 0 to 243)

I tried

for i, n in zip(daily1.columns, range(244)): asd=daily1.rename(columns={i:n}) asd 

but output has not shown...

Ideal output is

 0 1 2 3 4 5 6 7 8 9 ... 234 235 236 237 238 239 240 241 242 243 0 0 0 0 0 0 0 4 0 0 0 ... 640 777 674 842 786 865 809 674 679 852 1 0 0 0 0 0 0 0 0 0 0 ... 108 29 74 102 82 62 83 68 30 61 

Could I get some advice guys? Thank you

1 Answer 1

1

If you want to reorder the columns you can try that

columns = sorted(list(df.columns), reverse=False) df = df[columns] 

If you just want to rename the columns then you can try

df.columns = [i for i in range(df.shape[1])] 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.