Introduction
These libraries help you work with data easily. They let you organize, calculate, and show data in simple ways.
These libraries help you work with data easily. They let you organize, calculate, and show data in simple ways.
import pandas as pd import numpy as np import matplotlib.pyplot as plt
Use pd as a short name for Pandas to save typing.
Use np as a short name for NumPy for easy access to math functions.
import pandas as pd # Create a simple table (DataFrame) data = pd.DataFrame({'Name': ['Anna', 'Bob'], 'Age': [25, 30]}) print(data)
import numpy as np # Create an array of numbers numbers = np.array([1, 2, 3, 4]) print(numbers * 2)
import matplotlib.pyplot as plt # Make a simple line chart plt.plot([1, 2, 3], [4, 5, 6]) plt.title('Simple Line Chart') plt.show()
This program shows how to use Pandas to hold data, NumPy to calculate the average, and Matplotlib to draw a sales chart.
import pandas as pd import numpy as np import matplotlib.pyplot as plt # Create a DataFrame with sample data data = pd.DataFrame({ 'Day': ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'], 'Sales': [200, 220, 250, 210, 230] }) # Calculate average sales using NumPy average_sales = np.mean(data['Sales']) # Print the data and average print('Sales Data:') print(data) print(f'Average Sales: {average_sales}') # Plot sales over days plt.plot(data['Day'], data['Sales'], marker='o') plt.title('Sales Over Week') plt.xlabel('Day') plt.ylabel('Sales') plt.grid(True) plt.show()
Pandas is great for tables and labels.
NumPy is fast for math with many numbers.
Matplotlib helps you see data with pictures.
Pandas organizes data in tables.
NumPy does math on numbers quickly.
Matplotlib draws charts to understand data.
import numpy as np arr = np.array([1, 2, 3]) print(arr * 2)
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5]) plt.show()
Pass the test and this pattern moves unknown