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
Watch video How to Extract First & Last N Columns from pandas DataFrame in Python (2 Examples) | iloc Attribute online, duration hours minute second in high quality that is uploaded to the channel Statistics Globe 11 May 2022. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 880 times and liked it 8 visitors.