The Cable News Network is a multinational news channel and website headquartered in Atlanta
ommonly known as Fox News, is an American multinational conservative news and political commentary television channel and website based in New York City
is a 24-hour English-language news channel. It operates under the ownership of the Al Jazeera Media Network, which, in turn, is funded by the government of Qatar.
s an operational business division[1] of the British Broadcasting Corporation (BBC) responsible for the gathering and broadcasting of news and current affairs in the UK and around the world.
is the news division of the American broadcast television network NBC. The division operates under NBCUniversal Television and Streaming, a division of NBCUniversal, which is, in turn, a wholly owned subsidiary of Comcast.
s the news division of the American television network ABC. Its flagship program is the daily evening newscast ABC World News Tonight with David Muir; other programs include morning news-talk show Good Morning America, Nightline, Primetime, 20/20, and Sunday morning political affairs program This Week with George Stephanopoulos.
pip install google-api-python-client
Requirement already satisfied: google-api-python-client in c:\users\jki\appdata\local\anaconda3\lib\site-packages (2.114.0)Note: you may need to restart the kernel to use updated packages. Requirement already satisfied: httplib2<1.dev0,>=0.15.0 in c:\users\jki\appdata\local\anaconda3\lib\site-packages (from google-api-python-client) (0.22.0) Requirement already satisfied: google-auth<3.0.0.dev0,>=1.19.0 in c:\users\jki\appdata\local\anaconda3\lib\site-packages (from google-api-python-client) (2.26.2) Requirement already satisfied: google-auth-httplib2>=0.1.0 in c:\users\jki\appdata\local\anaconda3\lib\site-packages (from google-api-python-client) (0.2.0) Requirement already satisfied: google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0.dev0,>=1.31.5 in c:\users\jki\appdata\local\anaconda3\lib\site-packages (from google-api-python-client) (2.15.0) Requirement already satisfied: uritemplate<5,>=3.0.1 in c:\users\jki\appdata\local\anaconda3\lib\site-packages (from google-api-python-client) (4.1.1) Requirement already satisfied: googleapis-common-protos<2.0.dev0,>=1.56.2 in c:\users\jki\appdata\local\anaconda3\lib\site-packages (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0.dev0,>=1.31.5->google-api-python-client) (1.62.0) Requirement already satisfied: protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0.dev0,>=3.19.5 in c:\users\jki\appdata\local\anaconda3\lib\site-packages (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0.dev0,>=1.31.5->google-api-python-client) (4.25.2) Requirement already satisfied: requests<3.0.0.dev0,>=2.18.0 in c:\users\jki\appdata\local\anaconda3\lib\site-packages (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0.dev0,>=1.31.5->google-api-python-client) (2.31.0) Requirement already satisfied: cachetools<6.0,>=2.0.0 in c:\users\jki\appdata\local\anaconda3\lib\site-packages (from google-auth<3.0.0.dev0,>=1.19.0->google-api-python-client) (5.3.2) Requirement already satisfied: pyasn1-modules>=0.2.1 in c:\users\jki\appdata\local\anaconda3\lib\site-packages (from google-auth<3.0.0.dev0,>=1.19.0->google-api-python-client) (0.2.8) Requirement already satisfied: rsa<5,>=3.1.4 in c:\users\jki\appdata\local\anaconda3\lib\site-packages (from google-auth<3.0.0.dev0,>=1.19.0->google-api-python-client) (4.9) Requirement already satisfied: pyparsing!=3.0.0,!=3.0.1,!=3.0.2,!=3.0.3,<4,>=2.4.2 in c:\users\jki\appdata\local\anaconda3\lib\site-packages (from httplib2<1.dev0,>=0.15.0->google-api-python-client) (3.0.9) Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in c:\users\jki\appdata\local\anaconda3\lib\site-packages (from pyasn1-modules>=0.2.1->google-auth<3.0.0.dev0,>=1.19.0->google-api-python-client) (0.4.8) Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\jki\appdata\local\anaconda3\lib\site-packages (from requests<3.0.0.dev0,>=2.18.0->google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0.dev0,>=1.31.5->google-api-python-client) (2.0.4) Requirement already satisfied: idna<4,>=2.5 in c:\users\jki\appdata\local\anaconda3\lib\site-packages (from requests<3.0.0.dev0,>=2.18.0->google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0.dev0,>=1.31.5->google-api-python-client) (3.4) Requirement already satisfied: urllib3<3,>=1.21.1 in c:\users\jki\appdata\local\anaconda3\lib\site-packages (from requests<3.0.0.dev0,>=2.18.0->google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0.dev0,>=1.31.5->google-api-python-client) (1.26.16) Requirement already satisfied: certifi>=2017.4.17 in c:\users\jki\appdata\local\anaconda3\lib\site-packages (from requests<3.0.0.dev0,>=2.18.0->google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0.dev0,>=1.31.5->google-api-python-client) (2023.7.22)
# lets import libraries
from googleapiclient.discovery import build
import pandas as pd
import seaborn as sns
api_key = 'AIzaSyB24Kop04L1GlTgRCm1XtQ4KB2a4gaBOwA'
cnn_channel_id = ['UCupvZG-5ko_eiXAupbDfxWw' # CNN
]
youtube = build('youtube','v3',developerKey = api_key)
from googleapiclient.errors import HttpError
def get_channel_stats(youtube, cnn_channel_id):
all_data = []
try:
request = youtube.channels().list(
part='snippet,contentDetails,statistics',
id=','.join(cnn_channel_id)
)
response = request.execute()
for item in response.get('items', []):
snippet = item.get('snippet', {})
statistics = item.get('statistics', {})
data = {
'Channel_name': snippet.get('title', ''),
'Subscribers': statistics.get('subscriberCount', ''),
'Views': statistics.get('viewCount', ''),
'Total_videos': statistics.get('videoCount', '')
}
all_data.append(data)
except HttpError as e:
print(f"HTTP error occurred: {e}")
print(f"Request URL: {e.resp.request.url}")
print(f"Request body: {e.resp.request.body}")
return all_data
get_channel_stats(youtube, cnn_channel_id)
[{'Channel_name': 'CNN', 'Subscribers': '16000000', 'Views': '15240048075', 'Total_videos': '163094'}]
channel_statistics = get_channel_stats(youtube, channel_id)
cnn_channel_data =pd.DataFrame(channel_statistics)
cnn_channel_data
Channel_name | Subscribers | Views | Total_videos | |
---|---|---|---|---|
0 | CNN | 16000000 | 15240048075 | 163094 |
api_key = 'AIzaSyB24Kop04L1GlTgRCm1XtQ4KB2a4gaBOwA'
fox_channel_id = ['UCXIJgqnII2ZOINSWNOGFThA' # FOX News
]
youtube = build('youtube','v3',developerKey = api_key)
from googleapiclient.errors import HttpError
def get_channel_stats(youtube, fox_channel_id):
all_data = []
try:
request = youtube.channels().list(
part='snippet,contentDetails,statistics',
id=','.join(fox_channel_id)
)
response = request.execute()
for item in response.get('items', []):
snippet = item.get('snippet', {})
statistics = item.get('statistics', {})
data = {
'Channel_name': snippet.get('title', ''),
'Subscribers': statistics.get('subscriberCount', ''),
'Views': statistics.get('viewCount', ''),
'Total_videos': statistics.get('videoCount', '')
}
all_data.append(data)
except HttpError as e:
print(f"HTTP error occurred: {e}")
print(f"Request URL: {e.resp.request.url}")
print(f"Request body: {e.resp.request.body}")
return all_data
get_channel_stats(youtube, fox_channel_id)
[{'Channel_name': 'Fox News', 'Subscribers': '11000000', 'Views': '15999126832', 'Total_videos': '101095'}]
fox_news_channel_statistics = get_channel_stats(youtube, fox_channel_id)
fox_news_channel_data =pd.DataFrame(fox_news_channel_statistics)
fox_news_channel_data
Channel_name | Subscribers | Views | Total_videos | |
---|---|---|---|---|
0 | Fox News | 11000000 | 15999126832 | 101095 |
api_key = 'AIzaSyB24Kop04L1GlTgRCm1XtQ4KB2a4gaBOwA'
alajazeera_english_channel_id = ['UCNye-wNBqNL5ZzHSJj3l8Bg' # Aljazeera English
]
youtube = build('youtube','v3',developerKey = api_key)
from googleapiclient.errors import HttpError
def get_channel_stats(youtube, alajazeera_english_channel_id ):
all_data = []
try:
request = youtube.channels().list(
part='snippet,contentDetails,statistics',
id=','.join(alajazeera_english_channel_id )
)
response = request.execute()
for item in response.get('items', []):
snippet = item.get('snippet', {})
statistics = item.get('statistics', {})
data = {
'Channel_name': snippet.get('title', ''),
'Subscribers': statistics.get('subscriberCount', ''),
'Views': statistics.get('viewCount', ''),
'Total_videos': statistics.get('videoCount', '')
}
all_data.append(data)
except HttpError as e:
print(f"HTTP error occurred: {e}")
print(f"Request URL: {e.resp.request.url}")
print(f"Request body: {e.resp.request.body}")
return all_data
get_channel_stats(youtube, alajazeera_english_channel_id )
[{'Channel_name': 'Al Jazeera English', 'Subscribers': '12700000', 'Views': '4088036694', 'Total_videos': '110679'}]
alajazeera_channel_statistics = get_channel_stats(youtube, alajazeera_english_channel_id)
aljazeera_channel_data =pd.DataFrame(alajazeera_channel_statistics)
aljazeera_channel_data
Channel_name | Subscribers | Views | Total_videos | |
---|---|---|---|---|
0 | Al Jazeera English | 12700000 | 4088036694 | 110679 |
api_key = 'AIzaSyB24Kop04L1GlTgRCm1XtQ4KB2a4gaBOwA'
bbc_news_english_channel_id = [ 'UCQXHTFnQYFTqN0MqmNh9EIA' # BBC World Service
]
youtube = build('youtube','v3',developerKey = api_key)
from googleapiclient.errors import HttpError
def get_channel_stats(youtube, bbc_news_english_channel_id ):
all_data = []
try:
request = youtube.channels().list(
part='snippet,contentDetails,statistics',
id=','.join(bbc_news_english_channel_id)
)
response = request.execute()
for item in response.get('items', []):
snippet = item.get('snippet', {})
statistics = item.get('statistics', {})
data = {
'Channel_name': snippet.get('title', ''),
'Subscribers': statistics.get('subscriberCount', ''),
'Views': statistics.get('viewCount', ''),
'Total_videos': statistics.get('videoCount', '')
}
all_data.append(data)
except HttpError as e:
print(f"HTTP error occurred: {e}")
print(f"Request URL: {e.resp.request.url}")
print(f"Request body: {e.resp.request.body}")
return all_data
get_channel_stats(youtube, bbc_news_english_channel_id )
[{'Channel_name': 'BBC World Service', 'Subscribers': '378000', 'Views': '44415527', 'Total_videos': '965'}]
bbc_news_channel_statistics = get_channel_stats(youtube, bbc_news_english_channel_id)
bbc_news_channel_data =pd.DataFrame(bbc_news_channel_statistics)
bbc_news_channel_data
Channel_name | Subscribers | Views | Total_videos | |
---|---|---|---|---|
0 | BBC World Service | 378000 | 44415527 | 965 |
api_key = 'AIzaSyB24Kop04L1GlTgRCm1XtQ4KB2a4gaBOwA'
nbc_news_channel_id = [ 'UCeY0bbntWzzVIaj2z3QigXg' # NBC News
]
youtube = build('youtube','v3',developerKey = api_key)
from googleapiclient.errors import HttpError
def get_channel_stats(youtube, nbc_news_channel_id):
all_data = []
try:
request = youtube.channels().list(
part='snippet,contentDetails,statistics',
id=','.join(nbc_news_channel_id)
)
response = request.execute()
for item in response.get('items', []):
snippet = item.get('snippet', {})
statistics = item.get('statistics', {})
data = {
'Channel_name': snippet.get('title', ''),
'Subscribers': statistics.get('subscriberCount', ''),
'Views': statistics.get('viewCount', ''),
'Total_videos': statistics.get('videoCount', '')
}
all_data.append(data)
except HttpError as e:
print(f"HTTP error occurred: {e}")
print(f"Request URL: {e.resp.request.url}")
print(f"Request body: {e.resp.request.body}")
return all_data
get_channel_stats(youtube, nbc_news_channel_id )
[{'Channel_name': 'NBC News', 'Subscribers': '9580000', 'Views': '6857221109', 'Total_videos': '60314'}]
nbc_news_channel_statistics = get_channel_stats(youtube,nbc_news_channel_id)
nbc_news_channel_data =pd.DataFrame(nbc_news_channel_statistics)
nbc_news_channel_data
Channel_name | Subscribers | Views | Total_videos | |
---|---|---|---|---|
0 | NBC News | 9580000 | 6857221109 | 60314 |
api_key = 'AIzaSyB24Kop04L1GlTgRCm1XtQ4KB2a4gaBOwA'
abc_news_channel_id = [ 'UCBi2mrWuNuyYy4gbM6fU18Q' # ABC News
]
youtube = build('youtube','v3',developerKey = api_key)
from googleapiclient.errors import HttpError
def get_channel_stats(youtube, abc_news_channel_id ):
all_data = []
try:
request = youtube.channels().list(
part='snippet,contentDetails,statistics',
id=','.join(abc_news_channel_id)
)
response = request.execute()
for item in response.get('items', []):
snippet = item.get('snippet', {})
statistics = item.get('statistics', {})
data = {
'Channel_name': snippet.get('title', ''),
'Subscribers': statistics.get('subscriberCount', ''),
'Views': statistics.get('viewCount', ''),
'Total_videos': statistics.get('videoCount', '')
}
all_data.append(data)
except HttpError as e:
print(f"HTTP error occurred: {e}")
print(f"Request URL: {e.resp.request.url}")
print(f"Request body: {e.resp.request.body}")
return all_data
get_channel_stats(youtube, abc_news_channel_id )
[{'Channel_name': 'ABC News', 'Subscribers': '15700000', 'Views': '13971514055', 'Total_videos': '85577'}]
abc_news_channel_statistics = get_channel_stats(youtube, abc_news_channel_id)
abc_news_channel_data =pd.DataFrame(abc_news_channel_statistics)
abc_news_channel_data
Channel_name | Subscribers | Views | Total_videos | |
---|---|---|---|---|
0 | ABC News | 15700000 | 13971514055 | 85577 |
# Lets combine the data frames
cnn_channel_data
fox_news_channel_data
aljazeera_channel_data
bbc_news_channel_data
nbc_news_channel_data
abc_news_channel_data
# Combine DataFrames using concat
combined_news_channels_df = pd.concat([cnn_channel_data ,
fox_news_channel_data ,
bbc_news_channel_data ,
nbc_news_channel_data,
abc_news_channel_data
], ignore_index=True)
# Display the result
print(combined_news_channels_df)
Channel_name Subscribers Views Total_videos 0 CNN 16000000 15240048075 163094 1 Fox News 11000000 15999126832 101095 2 BBC World Service 378000 44415527 965 3 NBC News 9580000 6857221109 60314 4 ABC News 15700000 13971514055 85577
# lets have a look at the datatypes
combined_news_channels_df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 5 entries, 0 to 4 Data columns (total 4 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Channel_name 5 non-null object 1 Subscribers 5 non-null object 2 Views 5 non-null object 3 Total_videos 5 non-null object dtypes: object(4) memory usage: 292.0+ bytes
# lets change the datatypes to perform visualisations
combined_news_channels_df['Subscribers'] = pd.to_numeric(combined_news_channels_df['Subscribers'])
combined_news_channels_df['Views'] = pd.to_numeric(combined_news_channels_df['Views'])
combined_news_channels_df['Total_videos'] = pd.to_numeric(combined_news_channels_df['Total_videos'])
# letsconirm if the datatypes has changed
combined_news_channels_df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 5 entries, 0 to 4 Data columns (total 4 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Channel_name 5 non-null object 1 Subscribers 5 non-null int64 2 Views 5 non-null int64 3 Total_videos 5 non-null int64 dtypes: int64(3), object(1) memory usage: 292.0+ bytes
combined_news_channels_df
Channel_name | Subscribers | Views | Total_videos | |
---|---|---|---|---|
0 | CNN | 16000000 | 15240048075 | 163094 |
1 | Fox News | 11000000 | 15999126832 | 101095 |
2 | BBC World Service | 378000 | 44415527 | 965 |
3 | NBC News | 9580000 | 6857221109 | 60314 |
4 | ABC News | 15700000 | 13971514055 | 85577 |
import matplotlib.pyplot as plt
# Sort the DataFrame by 'Subscribers' in descending order
combined_news_channels_df_subscribers_sorted = combined_news_channels_df.sort_values(by='Subscribers', ascending=False)
# Plotting Subscribers in descending order
fig, axes = plt.subplots(nrows=3, ncols=1, figsize=(10, 15))
axes[0].bar(combined_news_channels_df_subscribers_sorted['Channel_name'], combined_news_channels_df_subscribers_sorted['Subscribers'], color='blue')
axes[0].set_title('Subscribers')
# Sort the DataFrame by 'Views' in descending order
combined_news_channels_df_views_sorted = combined_news_channels_df.sort_values(by='Views', ascending=False)
# Plotting Views in descending order
axes[1].bar(combined_news_channels_df_views_sorted['Channel_name'], combined_news_channels_df_views_sorted['Views'], color='green')
axes[1].set_title('Views')
# Sort the DataFrame by 'Total_videos' in descending order
combined_news_channels_df_total_videos_sorted = combined_news_channels_df.sort_values(by='Total_videos', ascending=False)
# Plotting Total Videos in descending order
axes[2].bar(combined_news_channels_df_total_videos_sorted['Channel_name'], combined_news_channels_df_total_videos_sorted['Total_videos'], color='orange')
axes[2].set_title('Total Videos')
# Adjust layout for better visibility
plt.tight_layout()
# Show the plot
plt.show()