ALL BUSINESS ENGLISH ARTICLES PYTHON

How to filter by product description and retail price – Python

SKU Product Description Color Size Stock Retail Price Brand Gender Standards
1001 Description 1001-S Green S 25 17 ROLY Male EN 388, EN 374
1002 Description 1001-M Green M 25 17 ROLY Male EN 388, EN 374
1003 Description 1001-L Green L 25 17 ROLY Male EN 388, EN 374
1004 Description 1002-S Blue S 18 16 ROLY Male EN 407
1005 Description 1002-M Blue M 18 16 ROLY Male EN 407
1006 Description 1003-S Blue S 35 16 ROLY Male EN 388
1007 Description 1003-M Blue M 35 16 ROLY Male EN 388
1008 Description 1003-L Blue L 35 16 ROLY Male EN 388
1009 Description 1004-S Blue S 45 15 ROLY Male EN 374
1010 Description 1004-M Blue M 45 15 ROLY Male EN 374
1011 Description 1004-L Blue L 45 16 ROLY Male EN 374
1012 Description 1005-L Blue L 47 13 ROLY Male EN 388

 Python script to filter by product description and retail price

Here is a simple Python script using pandas library to filter the data based on Product Description containing ‘Description 1001’ and Retail Price greater than 15. Please make sure you have the pandas library installed.

import pandas as pd

# Load the data from text file into DataFrame
df = pd.read_csv('demo_products_data_text_to_table5.txt', delimiter=';')

# Filter the data based on Product Description and Retail Price (e.g., filter for Description containing 'Description 1001' and Retail Price greater than 15)
filtered_df = df[(df['Product Description'].str.contains('Description 1001')) & (df['Retail Price'] > 15)]

# Display the filtered data
print(filtered_df)

This code assumes that your text file is in the same directory as your script and is named ‘demo_products_data_text_to_table5.txt‘. If the file name or location is different, please adjust the code accordingly. You may also modify the filter conditions as needed for your specific requirements.

Filtered data

Views: 6

Comments are closed.

Pin It