Reorder Columns in Pandas
Use double brackets to reorder columns in a DataFrame
Use the syntax DataFrame[["column1", "column2", "column3"]]
with the column names in the desired order to reorder the columns.
Output:
Output:
Use pandas.DataFrame.reindex()
to reorder columns in a DataFrame
pandas.DataFrame.reindex()
to reorder columns in a DataFrameCall pandas.DataFrame.reindex(columns=column_names)
with a list of the column names in the desired order as column_names
to reorder the columns.
Output:
Output:
Last updated