NumPy is a package library that helps perform mathematical operations of arrays and numbers. It also contains functions for reading data from files and plotting graphs. Here's a code example:
# adding 1 to each element using vectorization arr += 1
# printing the updated array print(arr)
Output: [2 3 4 5 6]
2. pandas:
pandas is a package library used for data manipulation and analysis. It provides functions for reading and writing data in various formats, such as CSV, Excel, and SQL. Here's a code example:
import pandas as pd
# reading a CSV file df = pd.read_csv('sales_data.csv')
# filtering rows with sales greater than 1000 df = df[df['sales'] > 1000]
# grouping by product and finding the mean sales mean_sales = df.groupby('product')['sales'].mean()
# printing the mean sales print(mean_sales)
Output: product A 2000 B 3000 C 2500 Name: sales, dtype: int64
3. Matplotlib:
Matplotlib is a package library used for visualization and plotting. It provides various types of plots, such as line, bar, scatter, and pie charts. Here's a code example:
import matplotlib.pyplot as plt
# creating data for a bar chart labels = ['Pizza', 'Burger', 'Sandwich', 'Pasta'] values = [22, 18, 15, 10]
# plotting a bar chart plt.bar(labels, values)
# adding labels and title to the chart plt.xlabel('Food items') plt.ylabel('Number of sales') plt.title('Popular food items')
Python Food - 54 examples found. These are the top rated real world Python examples of food.Food extracted from open source projects. You can rate examples to help us improve the quality of examples.