Drop First & Last N Columns from pandas DataFrame in Python (2 Examples) | Select & Remove Variables

Drop First & Last N Columns from pandas DataFrame in Python (2 Examples) | Select & Remove Variables

How to remove the first and last N variables from a pandas DataFrame in the Python programming language. More details: https://statisticsglobe.com/drop-firs... Python code of this video: import pandas as pd # Load pandas library data = pd.DataFrame({'x1':range(1, 7), # Create pandas DataFrame 'x2':range(0, 6), 'x3':['a', 'b', 'c', 'd', 'e', 'f'], 'x4':range(7, 1, - 1), 'x5':['x', 'x', 'y', 'y', 'x', 'x']}) print(data) # Print pandas DataFrame data_drop_first = data.iloc[:, 2:] # Remove first columns print(data_drop_first) # Print last columns data_drop_last = data.iloc[:, :3] # Remove last columns print(data_drop_last) # Print first 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