How to return the first and last N columns from a pandas DataFrame in the Python programming language. More details: https://statisticsglobe.com/extract-f...
Python code of this video:
import pandas as pd # Load pandas library
data = pd.DataFrame({'x1':range(10, 15), # Create pandas DataFrame
'x2':range(0, 5),
'x3':['a', 'b', 'c', 'd', 'e'],
'x4':range(8, 3, - 1),
'x5':['x', 'y', 'x', 'y', 'x']})
print(data) # Print pandas DataFrame
data_first_n = data.iloc[:, :3] # Select first columns
print(data_first_n) # Print first columns
data_last_n = data.iloc[:, 3:] # Select last columns
print(data_last_n) # Print last columns
Follow me on Social Media:
Facebook – Statistics Globe Page: / statisticsglobecom
Facebook – Group for Discussions & Questions: / statisticsglobe
LinkedIn – Statistics Globe Page: / statisticsglobe
LinkedIn – Group for Discussions & Questions: / 12555223
Twitter: / joachimschork
Music by bensound.com
On this page of the site you can watch the video online How to Extract First & Last N Columns from pandas DataFrame in Python (2 Examples) | iloc Attribute with a duration of hours minute second in good quality, which was uploaded by the user Statistics Globe 11 May 2022, share the link with friends and acquaintances, this video has already been watched 880 times on youtube and it was liked by 8 viewers. Enjoy your viewing!