Geo Python Doc (1) 7,8 Bavesh
Geo Python Doc (1) 7,8 Bavesh
DATE:
AIM:
To create a dataframe using pandas by performing the following
operations
Data Selection
Data Indexing
Handling missing data in normal attributes
Handling missing data in numeric attributes
Grouping operations
ALGORITHM:
Step 1: Start
Step 2: Import the required libraries (NumPy and Pandas)
Step 3: Create a DataFrame containing Name, Department, Salary and
Experience in Dictionary format ({ })
Step 4: Select specific columns and specific rows by using integer -
location indexing (iloc)
Step 5: Set any column as new index using set_index() and handle missing
data in normal attributes
Step 6: Perform group operations and find its mean using
mean() Step 7: Print the result
Step 8: Stop
PROGRAM:
import pandas as pd
import numpy as np
# 1. Creating a DataFrame
data = {
'Name': ['Alice', 'Bob', 'Charlie', 'David', np.nan],
'Department': ['HR', 'IT', 'HR', np.nan,
'Finance'], 'Salary': [50000, 60000, np.nan,
df = pd.DataFrame(data)
print("Original DataFrame:\n", df)
Original DataFrame:
Name Department Salary Experience
0 SARO HR 50000.0 2.0
1 MAITHU IT 60000.0 4.0
2 JITHESH HR NaN 5.0
3 GOKUL NaN 65000.0 3.0
4 NaN Finance 70000.0 NaN
RESULT:
Thus the python program for creating a data frame using pandas and
Register number: 2127240501036 Page:
performing various operation is implemented and executed successfully
DATE:
AIM:
To Write a python program to implement the following plots using
Matplotlib
i. Line plot
ii. Scatter plot
iii.Density plot
iv.Box plot
v.Histogram
ALGORITHM:
Step 1: Start
Step 2: Import the libraries matplotlib and numpy
Step 3: Create x values using np.array and y value as np.array
Step 4: Create the line plot, scatter plot, density plot and box plot using
plot(), scatter(), hist() and boxplot()
Step 5: Show the plot using plt.show() and print
them Step 6: Stop
PROGRAM:
import numpy as np
import matplotlib.pyplot as plt
# 1. Line Plot
plt.plot(x_values, y_values, marker='o',
linestyle=’-‘,color='b', label='Line Plot')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Line Plot with Limited Points')
plt.xlim(-1, 10)
plt.ylim(-2, 2)
plt.legend()
Register number: 2127240501036 Page:
plt.show()
# 2. Scatter Plot
plt.scatter(x_values, y_values, color='r', marker='x',
label='Scatter Plot')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Scatter Plot with Limited Points')
plt.xlim(-1, 10)
plt.ylim(-2, 2)
plt.legend()
plt.show()