Can we select columns of a dataframe in any order?


Can we select columns of a Pandas dataframe in any order?


You certainly can! When selecting multiple columns from a DataFrame, you can order the columns however you would like them to appear. This is particularly useful because if we wanted to see the data in a certain way different from the original column order, we can reorder them in the output however we need.


df = pd.DataFrame([
  ['Doe', 'Jane'],
  ['Law', 'Bob']],
  columns = ['last_name', 'first_name'])

# We can select the first_name column first, 
# then the last_name.
full_names = df[['first_name', 'last_name']]

How these library executing the month just by calling the string in column.I mean just by calling string of column in data frame?

There’s more code, but you import it from a module so you don’t have to repeat it again and define the same functions and variable all over again.

1 Like