import pandas as pd
import [Link] as plt
import numpy as np
import sys, os
# Global variable to store the selected CSV file
selected_csv = 'quantum_data.csv' # default
def menuset():
opt = ""
print()
print("^" * 37 , "Astronomy" , "^" * 37)
print('0. Select CSV File\n')
print('1. Read CSV\n')
print('2. Data Visualization\n')
print('3. Analysis\n')
print('4. Manipulation\n')
print('5. Exit\n')
opt = int(input('Enter your choice: '))
if opt == 0:
select_csv()
elif opt == 1:
read_csv()
elif opt == 2:
visuals()
elif opt == 3:
analysis()
elif opt == 4:
manipulation()
elif opt == 5:
print('Thanks')
exit()
def select_csv():
global selected_csv
print("\nAvailable CSV files:")
print("1. quantum_data.csv")
print("2. [Link]")
choice = int(input("Enter your choice: "))
if choice == 1:
selected_csv = 'quantum_data.csv'
elif choice == 2:
selected_csv = '[Link]'
else:
print("Invalid choice. Using default (quantum_data.csv).")
selected_csv = 'quantum_data.csv'
menuset()
# READ_CSV
def read_csv():
global selected_csv
print("^" * 43 , "Read_csv Menu" , "^" * 43)
a = pd.read_csv(selected_csv)
print(a)
menuset()
# DATA VISUALIZATION
def visuals():
opt = ""
print()
print("^" * 38 , "Data Visualization Menu" , "^" * 38)
print('1. Line Chart\n')
print('2. Bar Chart\n')
print('3. Pie Chart\n')
print('4. Histogram\n')
print('5. Exit\n')
opt = int(input('Enter your choice: '))
if opt == 1:
line()
elif opt == 2:
bar()
elif opt == 3:
pie()
elif opt == 4:
hist()
elif opt == 5:
a = input('Press m For Main Menu\nPress e For Exit\n')
if a == 'm':
menuset()
elif a == 'e':
print('Thanks!!')
exit()
def line():
df = pd.read_csv(selected_csv)
print([Link])
x = input("Enter column name for X-axis: ")
y = input("Enter column name for Y-axis: ")
if x in [Link] and y in [Link]:
[Link](x=x, y=y, kind='line')
[Link](f'{y} vs {x}')
[Link](x)
[Link](y)
[Link]()
else:
print("Invalid column names.")
menuset()
def bar():
df = pd.read_csv(selected_csv)
print([Link])
x = input("Enter column name for X-axis (categories): ")
y = input("Enter column name for Y-axis (values): ")
if x in [Link] and y in [Link]:
[Link](df[x], df[y], color='orange')
[Link](x)
[Link](y)
[Link](f'{y} vs {x} (Bar Chart)')
[Link](rotation=45)
plt.tight_layout()
[Link]()
else:
print("Invalid column names.")
menuset()
def pie():
df = pd.read_csv(selected_csv)
print([Link])
labels_col = input("Enter column name for Labels (categorical, like
names or IDs): ")
values_col = input("Enter column name for Values (numerical): ")
if labels_col in [Link] and values_col in [Link]:
df = [Link](10) # Limit to 10 for pie clarity
[Link](figsize=(8,8))
[Link](df[values_col], labels=df[labels_col], autopct='%1.1f%%',
startangle=90)
[Link](f'{values_col} Distribution by {labels_col}')
[Link]('equal')
[Link]()
else:
print("Invalid column names.")
menuset()
def hist():
df = pd.read_csv(selected_csv)
print([Link])
col = input("Enter column name for Histogram (numerical): ")
if col in [Link]:
[Link](df[col], bins='auto', facecolor='y', edgecolor='red')
[Link](f'Histogram of {col}')
[Link](col)
[Link]('Frequency')
[Link]()
else:
print("Invalid column name.")
menuset()
# DATA ANALYSIS
def analysis():
print()
print("^" * 40 , "Data Analysis Menu" , "^" * 40)
print('1. Top Records\n')
print('2. Bottom Records\n')
print('3. Print Particular Column\n')
print('4. Print Multiple Columns\n')
print('5. Display Complete Statistics (Aggregate Functions)\n')
print('6. Exit\n')
try:
opt = int(input('Enter your choice: '))
except ValueError:
print("Invalid input. Please enter a number.")
menuset()
return
if opt == 1:
top()
elif opt == 2:
bottom()
elif opt == 3:
single_column()
elif opt == 4:
multiple_column()
elif opt == 5:
aggregate()
elif opt == 6:
a = input('Press m For Main Menu\nPress e For Exit\n')
if a == 'm':
menuset()
elif a == 'e':
print('Thanks!!')
exit()
else:
print("Invalid choice.")
menuset()
def top():
df = pd.read_csv(selected_csv)
print("Top 5 Records:")
print([Link]())
menuset()
def bottom():
df = pd.read_csv(selected_csv)
print("Bottom 5 Records:")
print([Link]())
menuset()
def single_column():
df = pd.read_csv(selected_csv)
print("Available columns:", list([Link]))
c = input('Enter Column Name: ').strip()
if c in [Link]:
print(df[c])
else:
print("Invalid column name.")
menuset()
def multiple_column():
df = pd.read_csv(selected_csv)
print("Available columns:", list([Link]))
cols = input('Enter column names separated by commas: ').split(',')
cols = [[Link]() for col in cols]
missing_cols = [col for col in cols if col not in [Link]]
if missing_cols:
print("These columns are invalid or missing:", missing_cols)
else:
print(df[cols])
menuset()
def aggregate():
df = pd.read_csv(selected_csv)
print('1. Maximum')
print('2. Minimum')
print('3. Mean')
print('4. Count')
try:
d = int(input('Enter Your Choice: '))
except ValueError:
print("Invalid input.")
menuset()
return
if d in [1, 2, 3]:
print("Available columns:", list([Link]))
col = input("Enter column name: ").strip()
if col not in [Link]:
print("Invalid column name.")
menuset()
return
try:
numeric_series = pd.to_numeric(df[col], errors='coerce')
if numeric_series.isna().all():
print("Selected column is not numeric.")
else:
if d == 1:
print(f"Maximum of {col} = {numeric_series.max()}")
elif d == 2:
print(f"Minimum of {col} = {numeric_series.min()}")
elif d == 3:
print(f"Mean of {col} = {numeric_series.mean()}")
except Exception as e:
print("Error:", e)
elif d == 4:
print("Column-wise count of non-null values:")
print([Link]())
else:
print("Invalid choice.")
menuset()
# DATA MANIPULATION
def manipulation():
global selected_csv
print()
print("^" * 38 , "Data Manipulation Menu" , "^" * 38)
print('1. Insert a Row\n')
print('2. Delete a Row\n')
print('3. Exit\n')
opt = int(input('Enter your choice: '))
df = pd.read_csv(selected_csv)
if opt == 1:
print("Current columns:", list([Link]))
new_row = {}
for col in [Link]:
value = input(f"Enter value for '{col}': ")
new_row[col] = value
df = [Link]([df, [Link]([new_row])], ignore_index=True)
df.to_csv(selected_csv, index=False)
print("Row added successfully.")
print([Link]())
menuset()
elif opt == 2:
print(df)
try:
drop1 = int(input('Enter Row Index to Delete: '))
if 0 <= drop1 < len(df):
df = [Link]([Link][drop1])
df.reset_index(drop=True, inplace=True)
df.to_csv(selected_csv, index=False)
print("Row deleted successfully.")
print(df)
else:
print("Invalid index.")
except ValueError:
print("Invalid input.")
menuset()
elif opt == 3:
print('Thanks!!')
exit()
# Start the program
menuset()