Change Order of Columns in pandas DataFrame in Python (2 Examples) | Sort Variables Alphabetically

Change Order of Columns in pandas DataFrame in Python (2 Examples) | Sort Variables Alphabetically

Statistics Globe

54 года назад

298 Просмотров

How to rearrange the variables of a pandas DataFrame in the Python programming language. More details: https://statisticsglobe.com/change-order-of-columns-in-pandas-dataframe-python
Python code of this video:

import pandas as pd # Load pandas library

data = pd.DataFrame({'x3':range(1, 6), # Create example DataFrame
'x1':['a', 'b', 'c', 'd', 'e'],
'x4':[1, 1, 1, 1, 1],
'x2':['x', 'x', 'y', 'x', 'y']})
print(data) # Print example DataFrame

data_new1 = data.sort_index(axis=1)
print(data_new1)

data_new2 = data[['x2', 'x4', 'x1', 'x3']]
print(data_new2)

Follow me on Social Media:
Facebook – Statistics Globe Page: https://www.facebook.com/statisticsglobecom/
Facebook – R Programming Group for Discussions & Questions: https://www.facebook.com/groups/statisticsglobe
Facebook – Python Programming Group for Discussions & Questions: https://www.facebook.com/groups/statisticsglobepython
LinkedIn – Statistics Globe Page: https://www.linkedin.com/company/statisticsglobe/
LinkedIn – R Programming Group for Discussions & Questions: https://www.linkedin.com/groups/12555223/
LinkedIn – Python Programming Group for Discussions & Questions: https://www.linkedin.com/groups/12673534/
Twitter: https://twitter.com/JoachimSchork

Music by bensound.com

Тэги:

#statistics_globe #statistical_programming #python_programming #python_statistics #jupyter_notebook #python_language #python_tutorial #learn_python #python_code #python_programming_tutorial #data_science #data_scientist #learn_data_science #Change_Order_of_Columns_in_pandas_DataFrame #rearrange_the_variables_of_a_pandas_DataFrame #modify_and_sort_the_column_order_of_a_pandas_DataFrame #Order_Columns_of_pandas_DataFrame_Alphabetically #Order_Columns_of_pandas_DataFrame_Manually
Ссылки и html тэги не поддерживаются


Комментарии: