Interaction with Pandas, Matplotlib, and SciPy in NumPy Framework
NumPy is the foundation of scientific computing in Python. It interacts seamlessly with Pandas for data manipulation, Matplotlib for visualization, and SciPy for advanced mathematical operations.
1. Using NumPy with Pandas
Pandas leverages NumPy arrays for efficient data storage and manipulation.
Example:
import numpy as np import pandas as pd # Creating a NumPy array data = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) # Converting to a Pandas DataFrame df = pd.DataFrame(data, columns=['A', 'B', 'C']) print(df)
Result:
A Pandas DataFrame is created from a NumPy array.
2. Using NumPy with Matplotlib
Matplotlib is used for visualizing NumPy arrays.
Example:
import numpy as np import matplotlib.pyplot as plt # Creating NumPy array for plotting x = np.linspace(0, 10, 100) y = np.sin(x) # Plotting with Matplotlib plt.plot(x, y) plt.xlabel("X-axis") plt.ylabel("Y-axis") plt.title("Sine Wave") plt.show()
Result:
A sine wave graph is generated using NumPy and Matplotlib.
3. Using NumPy with SciPy
SciPy extends NumPy by providing advanced mathematical functions.
Example:
import numpy as np from scipy import integrate # Define a function to integrate def func(x): return np.sin(x) # Compute definite integral from 0 to pi result, _ = integrate.quad(func, 0, np.pi) print("Integral result:", result)
Result:
The integral of the sine function is computed using SciPy.
Conclusion
NumPy integrates well with Pandas for data manipulation, Matplotlib for visualization, and SciPy for advanced computations, making it a key library for scientific computing in Python.