pandas has reindex method that does it. You just need to give a list with the column names in the order you wish:
columns_titles = ["B","A"]
df=df.reindex(columns=columns_titles)
Cheers
More Related Contents:
- Pandas conditional creation of a series/dataframe column
- Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
- How to unnest (explode) a column in a pandas DataFrame, into multiple rows
- Why does concatenation of DataFrames get exponentially slower?
- Remove unwanted parts from strings in a column
- Combine Date and Time columns using python pandas
- Pandas/Python: Set value of one column based on value in another column
- Accessing Pandas column using squared brackets vs using a dot (like an attribute)
- Pandas Timedelta in Days
- how to get ticks every hour?
- How to add value labels on a bar chart
- How to remove blanks/NA’s from dataframe and shift the values up
- Why does my Pandas DataFrame not display new order using `sort_values`?
- How to check if a column exists in Pandas
- Difference(s) between merge() and concat() in pandas
- Seaborn showing scientific notation in heatmap for 3-digit numbers
- Format certain floating dataframe columns into percentage in pandas
- How can I see the formulas of an excel spreadsheet in pandas / python?
- Count distinct words from a Pandas Data Frame
- How to annotate each segment of a stacked bar chart
- subsetting a Python DataFrame
- How to use Pandas stylers for coloring an entire row based on a given column?
- pandas: combine two columns in a DataFrame
- Pandas query function not working with spaces in column names
- Numpy isnan() fails on an array of floats (from pandas dataframe apply)
- better way to drop nan rows in pandas
- How do I create a sum row and sum column in pandas?
- Python pandas cumsum() reset after hitting max
- Selecting a range of columns in a dataframe
- Pandas min() of selected row and columns