Rearranging columns in pandas has been asked before in many threads.
I can print
my columns and copy paste whatever I need to reorder in pandas
. However, I am wondering if I have more than 20 columns, can I rearrange using columns numbers? I know in R
this can be done something like this,
new_df <- my_df[,c(1:9, 11:21, 10)]
I attempted the same below in pandas
, but getting a SyntaxError
,
new_df = my_df[[:, 1:9, 11:21, 10]]
I have been searching and could not find a document to refer to get an answer. Is there anything like that in pandas
that I can do in one line like in R
?