0% found this document useful (0 votes)
5 views

Main code

Uploaded by

Jayant Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Main code

Uploaded by

Jayant Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Main code

Importing work
import pandas as pd
import matplotlib.pyplot as plt
from ast import literal_eval # To safely evaluate input lists

# Load the dataset with the language names as index


df = pd.read_csv("/content/programming_languages_popularity.csv", index_col="Language") #
Assuming 'Language' is a column

Main menu
def main_menu():
print("Main Menu")
print("1. Fetch data")
print("2. Dataframe Statistics")
print("3. Display Records")
print("4. Working on Records")
print("5. Working on Columns")
print("6. Search specific row/column")
print("7. Data Visualization")
print("8. Data Analytics")
print("9. Exit")

Working on Different menus

def statistics_menu(df):
while True:
print("Dataframe Statistics Menu")
print("1. Display the Transpose")
print("2. Display all column names")
print("3. Display the indexes")
print("4. Display the shape")
print("5. Display the dimension")
print("6. Display the data types of all columns")
print("7. Display the size")
print("8. Exit")
try:
ch2 = int(input("Enter choice: "))
print(" ")
if ch2 == 1:
print(df.T)
elif ch2 == 2:
print(df.columns)
elif ch2 == 3:
print(df.index)
elif ch2 == 4:
print(df.shape)
elif ch2 == 5:
print(df.ndim)
elif ch2 == 6:
print(df.dtypes)
elif ch2 == 7:
print(df.size)
elif ch2 == 8:
break
except ValueError:
print("Please enter a valid number.")
print(" ")

def display_records_menu(df):
while True:
print("Display Records Menu")
print("1. Top 5 Records")
print("2. Bottom 5 Records")
print("3. Specific number of records from the top")
print("4. Specific number of records from the bottom")
print("5. Details of a specific Language")
print("6. Display details of all languages")
print("7. Exit")
try:
ch3 = int(input("Enter choice: "))
print(" ")
if ch3 == 1:
print(df.head())
elif ch3 == 2:
print(df.tail())
elif ch3 == 3:
n = int(input("Enter how many records you want to display from the top: "))
print(" ")
print(df.head(n))
elif ch3 == 4:
n = int(input("Enter how many records you want to display from the bottom: "))
print(" ")
print(df.tail(n))
elif ch3 == 5:
lang = input("Enter the language name for which you want to see the details: ")
if lang in df.index:
print(df.loc[lang])
else:
print("Language not found")
elif ch3 == 6:
print(df)
elif ch3 == 7:
break
except ValueError:
print("Please enter a valid number.")
print(" ")

def working_on_records_menu(df):
while True:
print("Working on Records Menu")
print("1. Insert a specific language detail")
print("2. Delete a specific language detail")
print("3. Update a specific language detail")
print("4. Exit")
try:
ch4 = int(input("Enter choice: "))
print(" ")
if ch4 == 1:
language = input("Enter language name: ")
print(" ")
google_pop = int(input("Enter Google Trends Popularity: "))
print(" ")
github_repos = int(input("Enter GitHub Repositories: "))
print(" ")
job_postings = int(input("Enter Job Postings: "))
print(" ")
avg_salary = int(input("Enter Average Salary: "))
print(" ")
df.loc[language] = [google_pop, github_repos, job_postings, avg_salary]
print("Data successfully inserted")
elif ch4 == 2:
language = input("Enter language name whose data needs to be deleted: ")
print(" ")
if language in df.index:
df.drop(language, inplace=True)
print("Data successfully deleted")
else:
print("Language not found")
elif ch4 == 3:
language = input("Enter language name whose data needs to be updated: ")
print(" ")
if language in df.index:
google_pop = int(input("Enter Google Trends Popularity: "))
print(" ")
github_repos = int(input("Enter GitHub Repositories: "))
print(" ")
job_postings = int(input("Enter Job Postings: "))
print(" ")
avg_salary = int(input("Enter Average Salary: "))
print(" ")
df.loc[language] = [google_pop, github_repos, job_postings, avg_salary]
print("Data successfully updated")
else:
print("Language not found")
elif ch4 == 4:
break
except ValueError:
print("Please enter valid numeric data.")
print(" ")

def working_on_columns_menu(df):
while True:
print("Working on Columns Menu")
print("1. Insert a new column data")
print("2. Delete a specific column")
print("3. Exit")
try:
ch5 = int(input("Enter choice: "))
print(" ")
if ch5 == 1:
col_name = input("Enter new column/heading name: ")
print(" ")
det = literal_eval(input("Enter details corresponding to all languages (enclosed in [ ]):
"))
print(" ")
if len(det) == len(df):
df[col_name] = pd.Series(data=det, index=df.index)
print("Column inserted")
else:
print("Error: Length of data doesn't match number of languages.")
elif ch5 == 2:
col_name = input("Enter column name which needs to be deleted: ")
print(" ")
if col_name in df.columns:
df.drop([col_name], axis=1, inplace=True)
print("Column deleted")
else:
print("Column not found")
elif ch5 == 3:
break
except ValueError:
print("Please enter valid data.")
print(" ")

def search_menu(df):
while True:
print("Search Menu")
print("1. Search for the details of a specific language")
print("2. Search details of a specific column")
print("3. Exit")
try:
ch6 = int(input("Enter choice: "))
print(" ")
if ch6 == 1:
lang = input("Enter the name of the language whose details you want to see: ")
print(" ")
if lang in df.index:
print(df.loc[lang])
else:
print("Language not found")
elif ch6 == 2:
col_name = input("Enter column/heading name whose details you want to see: ")
print(" ")
if col_name in df.columns:
print(df[col_name])
else:
print("Column not found")
elif ch6 == 3:
break
except ValueError:
print("Please enter a valid choice.")
print(" ")

def data_visualization_menu(df):
while True:
print("Data Visualization Menu")
print("1. Scatter Plot: Google Trends Popularity vs. Average Salary")
print("2. Scatter Plot: GitHub Repositories vs. Job Postings")
print("3. Bar Chart: Google Trends Popularity by Language")
print("4. Horizontal Bar Chart: Average Salary by Language")
print("5. Scatter Plot: Google Trends Popularity vs Average Salary")
print("6. Exit")

try:
ch7 = int(input("Enter choice: "))
print(" ")
if ch7 == 1:
df.plot(kind='scatter', x='Google Trends Popularity', y='Average Salary', title='Google
Trends Popularity vs. Average Salary')
plt.show()
elif ch7 == 2:
df.plot(kind='scatter', x='GitHub Repositories', y='Job Postings', title='GitHub
Repositories vs. Job Postings')
plt.show()
elif ch7 == 3:
df.plot(kind='bar', x='Language', y='Google Trends Popularity', figsize=(10, 6),
color='skyblue', title='Google Trends Popularity of Programming Languages')
plt.show()
elif ch7 == 4: # Removed parentheses here
df.plot(kind='barh', x='Language', y='Average Salary', figsize=(10, 6), color='green',
title='Average Salary by Programming Language')
plt.show()
elif ch7 == 5:
df.plot(kind='scatter', x='Google Trends Popularity', y='Average Salary', figsize=(10,
6), color='blue', title='Google Trends Popularity vs Average Salary')
plt.show()
elif ch7 == 6: # No changes needed here
break
else:
print("Invalid choice, please try again.")
except ValueError:
print("Please enter a valid number.")
print(" ")

def data_analytics_menu(df):
while True:
print("Data Analytics Menu")
print("1. Display the language with the highest Google Trends Popularity")
print("2. Display the language with the most GitHub Repositories")
print("3. Display the language with the highest Average Salary")
print("4. Exit")
try:
ch8 = int(input("Enter choice: "))
print(" ")
if ch8 == 1:
print(df[df['Google Trends Popularity'] == df['Google Trends Popularity'].max()])
elif ch8 == 2:
print(df[df['GitHub Repositories'] == df['GitHub Repositories'].max()])
elif ch8 == 3:
print(df[df['Average Salary'] == df['Average Salary'].max()])
elif ch8 == 4:
break
except ValueError:
print("Please enter a valid choice.")
print(" ")

if __name__ == "__main__":
while True:
main_menu()
try:
ch = int(input("Enter your choice: "))
print(" ")
if ch == 1:
df = pd.read_csv("/content/programming_languages_popularity.csv",
index_col="Language")
print("Data successfully fetched")
elif ch == 2:
statistics_menu(df)
elif ch == 3:
display_records_menu(df)
elif ch == 4:
working_on_records_menu(df)
elif ch == 5:
working_on_columns_menu(df)
elif ch == 6:
search_menu(df)
elif ch == 7:
data_visualization_menu(df)
elif ch == 8:
data_analytics_menu(df)
elif ch == 9:
print("Exiting the program")
break
else:
print("Invalid choice, please try again.")
except ValueError:
print("Please enter a valid number.")
—----------------------------------------------------------------------------------------------------------------------------

You might also like