Natalia
Natalia

Reputation: 71

How to assign columns names in Pandas?

I got the filtered Pandas table (dataframe). Is it possible to assign manually using UI interface the columns names and move fields across dataframe by mouse?

Upvotes: 0

Views: 135

Answers (2)

Syntax Error
Syntax Error

Reputation: 72

If you need to rename columns , you can do the following :

df.rename(columns={'col_a':'new_col_a'}, inplace=True)

For alignment you can simply follow @mitoRibo suggestion.

Upvotes: 1

mitoRibo
mitoRibo

Reputation: 4548

Here's an example of how to change the order of columns in a table if that's your question

import pandas as pd

df = pd.DataFrame({
    'c':['c1','c2','c3'],
    'a':['a1','a2','a3'],
    'b':['b1','b2','b3'],
})

print('Original column order')
print(df)
#Original column order
#    c   a   b
#0  c1  a1  b1
#1  c2  a2  b2
#2  c3  a3  b3


reordered_df = df[['a','b','c']]
print('Reorderd columns')
print(reordered_df)
#Reorderd columns
#    a   b   c
#0  a1  b1  c1
#1  a2  b2  c2
#2  a3  b3  c3

Upvotes: 1

Related Questions