Slice pandas DataFrame by Index in Python (Example) | Split at Particular Row | How to Divide Data

Published: 06 July 2022
on channel: Statistics Globe
2,410
20

How to split a pandas DataFrame at a certain row index position in the Python programming language. More details: https://statisticsglobe.com/slice-pan...
Python code of this video:

import pandas as pd # Load pandas

data = pd.DataFrame({'x1':range(10, 18), # Create pandas DataFrame
'x2':['a', 'b', 'b', 'c', 'd', 'a', 'b', 'd'],
'x3':range(27, 19, - 1),
'x4':['x', 'z', 'y', 'y', 'x', 'y', 'z', 'x']})
print(data) # Print pandas DataFrame

split_point = 3 # Define split point
print(split_point) # Print split point
3

data_upper = data.iloc[:split_point] # Create upper data set
print(data_upper) # Print DataFrame of upper rows

data_lower = data.iloc[split_point:] # Create lower data set
print(data_lower) # Print DataFrame of lower rows

Follow me on Social Media:
Facebook – Statistics Globe Page:   / statisticsglobecom  
Facebook – R Programming Group for Discussions & Questions:   / statisticsglobe  
Facebook – Python Programming Group for Discussions & Questions:   / statisticsglobepython  
LinkedIn – Statistics Globe Page:   / statisticsglobe  
LinkedIn – R Programming Group for Discussions & Questions:   / 12555223  
LinkedIn – Python Programming Group for Discussions & Questions:   / 12673534  
Twitter:   / joachimschork  

Music by bensound.com


Watch video Slice pandas DataFrame by Index in Python (Example) | Split at Particular Row | How to Divide Data online without registration, duration hours minute second in high quality. This video was added by user Statistics Globe 06 July 2022, don't forget to share it with your friends and acquaintances, it has been viewed on our site 2,410 once and liked it 20 people.