# 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.

```
print(df)
```

**Output:**

```
   A  B  C
0  1  4  7
1  2  5  8
2  3  6  9
```

```
df = df[["C", "A", "B"]]
print(df)
```

**Output:**

```
   C  A  B
0  7  1  4
1  8  2  5
2  9  3  6
```

### Use `pandas.DataFrame.reindex()` to reorder columns in a DataFrame

Call `pandas.DataFrame.reindex(columns=column_names)` with a list of the column names in the desired order as `column_names` to reorder the columns.

```
print(df)
```

**Output:**

```
   A  B  C
0  1  4  7
1  2  5  8
2  3  6  9
```

```
column_names = ["C", "A", "B"]
df = df.reindex(columns=column_names)
print(df)
```

**Output:**

```
   C  A  B
0  7  1  4
1  8  2  5
2  9  3  6
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.smhuda.com/programming/python/reorder-columns-in-pandas.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
