0% found this document useful (0 votes)
125 views4 pages

YouTube Data Viewer Code Copiable

The document is a Python script that reads YouTube advertising revenue and subscriber data from CSV files and presents a menu-driven interface for visualizing this data. Users can choose between displaying revenue or subscriber information using various chart types including bar, pie, line, horizontal bar, and scatter charts. The program continues to prompt the user for choices until they decide to exit.

Uploaded by

dadaji543210
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
125 views4 pages

YouTube Data Viewer Code Copiable

The document is a Python script that reads YouTube advertising revenue and subscriber data from CSV files and presents a menu-driven interface for visualizing this data. Users can choose between displaying revenue or subscriber information using various chart types including bar, pie, line, horizontal bar, and scatter charts. The program continues to prompt the user for choices until they decide to exit.

Uploaded by

dadaji543210
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

import pandas as pd

import matplotlib.pyplot as plt

# Read the CSV file


data1 = pd.read_csv("C:\Users\Lab4H\Documents\rijoip\YT project\revenue_data.csv")
data2 = pd.read_csv("C:\Users\Lab4H\Documents\rijoip\YT project\subscribers.csv")

# Welcome message
print("Welcome to the Data Viewer!")
print("YouTube advertising revenue 2014 to 2024 ($bn)")

# Create a menu-driven program


while True:
print("\nChoose an option:")
print("1. Display YouTube advertising revenue")
print("2. Display YouTube Premium subscribers")
print("3. Exit")
choice = int(input("Enter your choice: "))

if choice == 1:
while True:
print("\nChoose a chart type:")
print("1. Bar chart")
print("2. Pie chart")
print("3. Line chart")
print("4. Horizontal bar chart")
print("5. Scatter chart")
print("6. Exit")
chart_choice = input("Enter your choice: ")

if chart_choice in ['Bar','Pie','Line','HBar','Scatter chart','Exit']:


year = 'Year'
r_column = 'Revenue ($bn)'

if chart_choice == 'Bar':
plt.figure(figsize=(10, 6))
plt.bar(data1[year], data1[r_column], color='orange', edgecolor="purple",
label='Revenue')
plt.title('YouTube advertising Revenue')
plt.xlabel("Year")
plt.ylabel("Revenue($bn)")
plt.xticks(rotation=45)
plt.legend()
plt.show()

elif chart_choice == 'Pie':


plt.figure(figsize=(12, 12), dpi=100)
plt.pie(data1[r_column], labels=data1[year], autopct='%1.1f%%',
startangle=140, textprops={'fontsize': 14}, labeldistance=1.1)
plt.title("YouTube advertising Revenue", fontsize=18)
plt.show()

elif chart_choice == 'Line':


plt.figure(figsize=(10, 6))
plt.plot(data1[year], data1[r_column], marker='o', label='Revenue',
color='red')
plt.title("YouTube advertising Revenue")
plt.xlabel("Year")
plt.ylabel("Revenue($bn)")
plt.xticks(rotation=45)
plt.legend()
plt.grid()
plt.show()

elif chart_choice == 'HBar':


plt.figure(figsize=(10, 6))
plt.barh(data1[year], data1[r_column], color='cyan', edgecolor="magenta",
label='Revenue')
plt.title("YouTube advertising Revenue")
plt.xlabel("Year")
plt.ylabel("Revenue($bn)")
plt.legend()
plt.show()

elif chart_choice == 'Scatter chart':


plt.figure(figsize=(10, 6))
plt.scatter(data1[year], data1[r_column], color='purple', label='Revenue')
plt.title("YouTube advertising Revenue")
plt.xlabel("Year")
plt.ylabel("Revenue($bn)")
plt.xticks(rotation=45)
plt.legend()
plt.show()

elif chart_choice == 'Exit':


next_choice = input("Do you want to view Youtube (R)evenue or (P)remium data?
: ")
if next_choice == 'R':
continue
elif next_choice == 'P':
break

elif choice == 2:
while True:
print("\nChoose a chart type for displaying:")
print("1. Bar chart")
print("2. Pie chart")
print("3. Line chart")
print("4. Horizontal bar chart")
print("5. Scatter chart")
print("6. Exit")
download_chart_choice = input("Enter your choice: ")

if download_chart_choice in ['Bar','Pie','Line','HBar','Scatter chart','Exit']:


year = 'Year'
r_column = 'Subscribers (mm)'

if download_chart_choice == 'Bar':
plt.figure(figsize=(10, 6))
plt.bar(data2[year], data2[r_column], color='pink', edgecolor="black",
label='Premium Revenue')
plt.title('YouTube Premium Revenue')
plt.xlabel("Year")
plt.ylabel("Subscribers (mm)")
plt.xticks(rotation=45)
plt.legend()
plt.show()

elif download_chart_choice == 'Pie':


plt.figure(figsize=(8, 8))
plt.pie(data2[r_column], labels=data2[year], autopct='%1.1f%%',
startangle=140)
plt.title("YouTube Premium Revenue")
plt.show()

elif download_chart_choice == 'Line':


plt.figure(figsize=(10, 6))
plt.plot(data2[year], data2[r_column], marker='p', label='Premium Revenue',
color='yellow')
plt.title("YouTube Premium Revenue")
plt.xlabel("Year")
plt.ylabel("Subscribers (mm)")
plt.xticks(rotation=45)
plt.legend()
plt.grid()
plt.show()

elif download_chart_choice == 'HBar':


plt.figure(figsize=(10, 6))
plt.barh(data2[year], data2[r_column], color='purple', edgecolor="cyan",
label='Premium Revenue')
plt.title("YouTube Premium Revenue")
plt.xlabel("Year")
plt.ylabel("Subscribers (mm)")
plt.legend()
plt.show()

elif download_chart_choice == 'Scatter chart':


plt.figure(figsize=(10, 6))
plt.scatter(data2[year], data2[r_column], color='blue', label='Premium
Revenue')
plt.title("YouTube Premium Revenue")
plt.xlabel("Year")
plt.ylabel("Subscribers (mm)")
plt.xticks(rotation=45)
plt.legend()
plt.show()

elif download_chart_choice == 'Exit':


next_choice = input("Do you want to view Youtube (R)evenue or (P)remium data? : ")
if next_choice == 'R':
break
elif next_choice == 'P':
continue

elif choice == 3:
print("\nYou are exiting\nThank you for using the Data Viewer! Goodbye!")
break

You might also like