How to Create Subset of pandas DataFrame in Python (Example) | Subsetting Data by Logical Condition

preview_player
Показать описание
Python code of this video:

import pandas as pd # Import pandas library in Python

data = pd.DataFrame({'x1':['a', 'b', 'c', 'd', 'e', 'f', 'g'], # Create pandas DataFrame
'x2':range(7, 0, - 1),
'x3':[1, 2, 1, 4, 2, 3, 1]})
print(data) # Print pandas DataFrame

print(data_range) # Print DataFrame subset

Follow me on Social Media:

Рекомендации по теме
Комментарии
Автор

Hi, I love your videos. I want to ask you a python question. I have a dataset containing sales data of 50 stores by month e.g., Jan data of 50 stores sales then Feb and so on. I am trying to model a Linear Regression loop in python for each each shop predictive sales. The model will run 50 times as there are 50 shops. I want to know how to subset unique datapoint for individual shop.. I am using Nested For loop with i and j operators with logic like i==j to get subsets. Is there easier way of creating subset so that with each loop starts.. Code will only take out 12 datapoints (12 months) of that particular shop out of the dataframe and then ML model runs.. give predicted value and then Loop goes to the next shop. I have unique shop number. Kindly let me know. Thank you.

aakashniture