Documents 12-28 081644 PDF
Documents 12-28 081644 PDF
INDEX
1.Requirement
2.Hardware
3.Source Code
4.Code Explain
5.Screenshot
6.Bibliography
Source Code
import pandas as pd
def create_dataframe():
df = pd.DataFrame(data)
return (df)
def plot_data(df):
plt.figure(figsize=(8, 6))
plt.xlabel('Name', fontsize=12)
plt.ylabel('Salary', fontsize=12)
plt.show()
def authenticate(users):
while True:
if user_password != users[user_name]:
def add_entry(df):
df = df.append(new_entry, ignore_index=True)
print(f"Added entry: {new_entry}")
return (df)
def delete_entry(df):
if name_to_delete in df['Name'].values:
df = df[df['Name'] != name_to_delete]
else:
return (df)
def update_entry(df):
if name_to_update in df['Name'].values:
else:
def view_data(df):
print("\nCurrent Dataframe:")
print(df)
def main():
authenticate(users)
df = create_dataframe()
while True:
print("\nOptions:")
print("6. Exit")
view_data(df)
df = add_entry(df)
df = delete_entry(df)
df = update_entry(df)
plot_data(df)
break
else:
if __name__ == "__main__":
main()
Code
Explanation :
Import Libraries :
pandas: Used for data manipulation and analysis. In this program, it's used
to create and manage a DataFrame.
matplotlib.pyplot: Used for data visualization. It creates the bar chart for the
salary distribution.
def create_dataframe():
data = {
df = pd.DataFrame(data)
return df
Creates a dictionary with data about employees: their names, ages, and
salaries.
Converts this dictionary into a pandas DataFrame.
Returns the DataFrame, which will act as the core data structure for this
program.
2.Plotting Data
def plot_data(df):
plt.figure(figsize=(8, 6))
plt.xlabel('Name', fontsize=12)
plt.ylabel('Salary', fontsize=12)
plt.show()
3.User Authentication
def authenticate(users):
while True:
continue
if user_password != users[user_name]:
continue
break
4.Add an Entry
def add_entry(df):
return df
Prompts the user to input a new entry's name, age, and salary.
Creates a dictionary (new_entry) for the new row.
df.append(): Adds the new entry to the DataFrame.
Returns the updated DataFrame.
5.Delete an Entry
def delete_entry(df):
if name_to_delete in df['Name'].values:
df = df[df['Name'] != name_to_delete]
else:
return df
6.Update an Entry
def update_entry(df):
if name_to_update in df['Name'].values:
index = df[df['Name'] == name_to_update].index[0]
else:
return df
8.Main Function
def main():
users = {
authenticate(users)
df = create_dataframe()
while True:
print("\nOptions:")
print("6. Exit")
if choice == "1":
view_data(df)
df = add_entry(df)
df = delete_entry(df)
df = update_entry(df)
plot_data(df)
break
else:
break else:
Ensures the main()function runs only when the script is executed directly.
Screenshots :
Authentication Process :-
When you run the script, it will prompt for a username and password.
Example:
If you enter an incorrect name or password, it will keep asking until you
provide the correct credentials.
Options:
Option 1: View Data
Options:
Output Example:
Output:
The updated data will now include Ethan.
Output:
Output:
Option 5: Visualise Data
Output:
Option 6: Exit
Output: