Exploring Inventory Data with pandas
Pyyhkäise näyttääksesi valikon
Inventory data is at the heart of supply chain management. You work with information such as stock levels, product IDs, and warehouse locations to ensure the right products are available at the right place and time. Tracking inventory allows you to prevent stockouts, reduce excess inventory, and optimize warehouse operations. By analyzing this data, you can make better decisions about replenishment, distribution, and resource allocation.
1234567891011import pandas as pd # Create a DataFrame to represent inventory data = { 'product_id': ['A101', 'A101', 'B205', 'B205', 'C309', 'C309'], 'warehouse': ['North', 'South', 'North', 'South', 'North', 'South'], 'stock': [15, 7, 25, 5, 12, 3] } inventory_df = pd.DataFrame(data) print(inventory_df)
With your inventory data organized in a pandas DataFrame, you can begin analyzing stock across products and warehouses. Calculating the total stock per product gives you a clear view of overall inventory health. To do this, group the data by product_id and sum the stock values. Once you have total stock per product, you can identify products with low inventory by filtering for those whose total stock falls below a certain threshold, such as 10 units. This approach helps you quickly spot which products need replenishment.
123456789# Calculate total stock per product total_stock = inventory_df.groupby('product_id')['stock'].sum() print("Total stock per product:") print(total_stock) # Identify products with low inventory (stock < 10) low_stock = total_stock[total_stock < 10] print("\nProducts with low inventory:") print(low_stock)
1. What pandas method would you use to group inventory data by product?
2. Why is it important to identify products with low stock in supply chain management?
3. Fill in the blank: To filter rows in a DataFrame where stock is less than 10, use df[____].
Kiitos palautteestasi!
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme