Samsung is a big name in phone companies and has emerged as one of the top mobile brands in the world. It is a South Korean company founded on 1st March 1938. It is one of the most trusted brands in the world because of the top-notch facilities provided by the company and its long-lasting smartphones. The smartphones sold by this company are very much user-friendly, the best innovative software, proper customer care facility, cost-effective, etc.
It is one of the most premium mobile brands in the world. It is an American multinational technology company and is one of the biggest tech companies in the world. It was founded on April 1st, 1976 by Steve Jobs, Steve Wozniak, Ronald Wayne. The top smartphone hand of this company includes Apple iPhone 11, iPhone 11 Pro, iPhone X, iPhone XS Max, iPhone XR, iPhone 8, iPhone 8 Plus, iPhone SE.
It’s one of the wide-ranging smartphone brands in the world. It is a Chinese multinational company founded in 1987 by Ren Zhengfei. Popular handsets launched by this company are Huawei P30 Pro, Huawei Mate 20 Pro, Huawei P30, etc.
It is a Chinese multinational company founded in April 2010 by Lei Jun. With just a few years of its release, it has given a tough competition to its competitors. It’s the world’s 4th most valuable technology startup. Popular smartphones released by this company are Mi 10 Ultra, Redmi Note 9 Pro, Redmi Note 9, Redmi 9, Redmi Note 8, Poco F2 Pro, and Redmi Note 8 pro.
Guangdong OPPO Mobile Telecommunication Corp., Ltd, stylized as OPPO, is a Chinese company founded by Tony Chen in 2001. Some popular handset launched by the company is OPPO A31, OPPO F15, OPPO A5, OPPO F9, OPPO A9, OPPO Reno2, OPPO F3, F5, F7, F11 Pro, F5 Youth, OPPO A83.
VIVO Communication Technology Co. Ltd. Is a Chinese tech company founded in 2009 by Shen Wei. Vivo offers a wide range of phones with great features and specifications. Popular smartphones launched by the company are Vivo V17 Pro, VIVO Z1x, VIVO S1 Pro, VIVO S1, VIVO V17, VIVOZ1 Pro, VIVO S1, VIVO U20, VIVO U10, VIVO V15, VIVO Y11.
It’s an American multinational telecommunications company in 1928 founded by Paul and Joseph Galvin. After facing a loss of $4.3 billion from 2007 to 2009. The company got divided into two independent public companies, Motorola Mobility and Motorola Solutions in 2011. Popular mobiles launched by this company are Motorola Razr, Mate X, MOTO G8 Plus, MOTO Z4, Motorola One Action, MOTO Z3, MOTO G7 Power, MOTO G7 Plus and Motorola One Vision.
# lets import libraries
from googleapiclient.discovery import build
import pandas as pd
import seaborn as sn
# Function to get channel statistics
api_key = 'AIzaSyB24Kop04L1GlTgRCm1XtQ4KB2a4gaBOwA'
SAMSUNG_channel_id = ['UCWwgaK7x0_FR1goeSRazfsQ' # SAMSUNG
]
youtube = build('youtube','v3',developerKey = api_key)
from googleapiclient.errors import HttpError
def get_channel_stats(youtube, SAMSUNG_channel_id):
all_data = []
try:
request = youtube.channels().list(
part='snippet,contentDetails,statistics',
id=','.join(SAMSUNG_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,SAMSUNG_channel_id)
[{'Channel_name': 'Samsung', 'Subscribers': '6710000', 'Views': '1811453473', 'Total_videos': '2129'}]
channel_statistics = get_channel_stats(youtube, SAMSUNG_channel_id)
SAMSUNG_channel_data =pd.DataFrame(channel_statistics)
SAMSUNG_channel_data
Channel_name | Subscribers | Views | Total_videos | |
---|---|---|---|---|
0 | Samsung | 6710000 | 1811453473 | 2129 |
# Function to get channel statistics
api_key = 'AIzaSyB24Kop04L1GlTgRCm1XtQ4KB2a4gaBOwA'
APPLE_channel_id = ['UCE_M8A5yxnLfW0KghEeajjw' # APPLE
]
youtube = build('youtube','v3',developerKey = api_key)
from googleapiclient.errors import HttpError
def get_channel_stats(youtube, APPLE_channel_id):
all_data = []
try:
request = youtube.channels().list(
part='snippet,contentDetails,statistics',
id=','.join(APPLE_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,APPLE_channel_id)
[{'Channel_name': 'Apple', 'Subscribers': '18700000', 'Views': '1187698196', 'Total_videos': '191'}]
channel_statistics = get_channel_stats(youtube, APPLE_channel_id)
APPLE_channel_data =pd.DataFrame(channel_statistics)
APPLE_channel_data
Channel_name | Subscribers | Views | Total_videos | |
---|---|---|---|---|
0 | Apple | 18700000 | 1187698196 | 191 |
# Function to get channel statistics
api_key = 'AIzaSyB24Kop04L1GlTgRCm1XtQ4KB2a4gaBOwA'
HUAWEI_channel_id = ['UCtjV1_XU6gvPYyreaFScxBQ' # HUAWEI
]
youtube = build('youtube','v3',developerKey = api_key)
from googleapiclient.errors import HttpError
def get_channel_stats(youtube, HUAWEI_channel_id):
all_data = []
try:
request = youtube.channels().list(
part='snippet,contentDetails,statistics',
id=','.join(HUAWEI_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,HUAWEI_channel_id)
[{'Channel_name': 'Huawei', 'Subscribers': '1410000', 'Views': '346045185', 'Total_videos': '2655'}]
channel_statistics = get_channel_stats(youtube, HUAWEI_channel_id)
HUAWEI_channel_data =pd.DataFrame(channel_statistics)
HUAWEI_channel_data
Channel_name | Subscribers | Views | Total_videos | |
---|---|---|---|---|
0 | Huawei | 1410000 | 346045185 | 2655 |
# Function to get channel statistics
api_key = 'AIzaSyB24Kop04L1GlTgRCm1XtQ4KB2a4gaBOwA'
XIAOMI_channel_id = ['UCCspJ6mFfCwOV4qFjZWi2wg' # XIAOMI
]
youtube = build('youtube','v3',developerKey = api_key)
from googleapiclient.errors import HttpError
def get_channel_stats(youtube, XIAOMI_channel_id):
all_data = []
try:
request = youtube.channels().list(
part='snippet,contentDetails,statistics',
id=','.join(XIAOMI_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,XIAOMI_channel_id)
[{'Channel_name': 'Xiaomi', 'Subscribers': '3010000', 'Views': '654368313', 'Total_videos': '1460'}]
channel_statistics = get_channel_stats(youtube, XIAOMI_channel_id)
XIAOMI_channel_data =pd.DataFrame(channel_statistics)
XIAOMI_channel_data
Channel_name | Subscribers | Views | Total_videos | |
---|---|---|---|---|
0 | Xiaomi | 3010000 | 654368313 | 1462 |
# Function to get channel statistics
api_key = 'AIzaSyB24Kop04L1GlTgRCm1XtQ4KB2a4gaBOwA'
OPPO_channel_id = ['UC1ET-1gMajGNKzOvm2e_D7Q' # OPPO
]
youtube = build('youtube','v3',developerKey = api_key)
from googleapiclient.errors import HttpError
def get_channel_stats(youtube, OPPO_channel_id):
all_data = []
try:
request = youtube.channels().list(
part='snippet,contentDetails,statistics',
id=','.join(OPPO_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,OPPO_channel_id)
[{'Channel_name': 'OPPO', 'Subscribers': '433000', 'Views': '127753852', 'Total_videos': '458'}]
channel_statistics = get_channel_stats(youtube, OPPO_channel_id)
OPPO_channel_data =pd.DataFrame(channel_statistics)
OPPO_channel_data
Channel_name | Subscribers | Views | Total_videos | |
---|---|---|---|---|
0 | OPPO | 433000 | 127753852 | 458 |
# Function to get channel statistics
api_key = 'AIzaSyB24Kop04L1GlTgRCm1XtQ4KB2a4gaBOwA'
VIVO_channel_id = ['UCksLuuLNvTuQtH-u8MDfARg' # VIVO
]
youtube = build('youtube','v3',developerKey = api_key)
from googleapiclient.errors import HttpError
def get_channel_stats(youtube, VIVO_channel_id):
all_data = []
try:
request = youtube.channels().list(
part='snippet,contentDetails,statistics',
id=','.join(VIVO_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,VIVO_channel_id)
[{'Channel_name': 'vivo Thailand', 'Subscribers': '917000', 'Views': '819812214', 'Total_videos': '325'}]
channel_statistics = get_channel_stats(youtube, VIVO_channel_id)
VIVO_channel_data =pd.DataFrame(channel_statistics)
VIVO_channel_data
Channel_name | Subscribers | Views | Total_videos | |
---|---|---|---|---|
0 | vivo Thailand | 917000 | 819812214 | 325 |
# Function to get channel statistics
api_key = 'AIzaSyB24Kop04L1GlTgRCm1XtQ4KB2a4gaBOwA'
MOTOROLA_channel_id = ['UCJkBIeTewoQGgtviUe5LH_g' # MOTOROLA
]
youtube = build('youtube','v3',developerKey = api_key)
from googleapiclient.errors import HttpError
def get_channel_stats(youtube, MOTOROLA_channel_id):
all_data = []
try:
request = youtube.channels().list(
part='snippet,contentDetails,statistics',
id=','.join(MOTOROLA_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
channel_statistics = get_channel_stats(youtube, MOTOROLA_channel_id)
MOTOROLA_channel_data =pd.DataFrame(channel_statistics)
MOTOROLA_channel_data
Channel_name | Subscribers | Views | Total_videos | |
---|---|---|---|---|
0 | Motorola | 351000 | 6502819 | 190 |
# Lets combine the data frames
# Combine DataFrames using concat
combined_phone_brands_channels_df = pd.concat([SAMSUNG_channel_data ,
APPLE_channel_data ,
HUAWEI_channel_data ,
XIAOMI_channel_data ,
OPPO_channel_data,
VIVO_channel_data,
MOTOROLA_channel_data,
], ignore_index=True)
# Display the result
print(combined_phone_brands_channels_df)
Channel_name Subscribers Views Total_videos 0 Samsung 6710000 1811453473 2129 1 Apple 18700000 1187698196 191 2 Huawei 1410000 346045185 2655 3 Xiaomi 3010000 654368313 1462 4 OPPO 433000 127753852 458 5 vivo Thailand 917000 819812214 325 6 Motorola 351000 6502819 190
# lets have a look at the datatypes
combined_phone_brands_channels_df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 7 entries, 0 to 6 Data columns (total 4 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Channel_name 7 non-null object 1 Subscribers 7 non-null object 2 Views 7 non-null object 3 Total_videos 7 non-null object dtypes: object(4) memory usage: 356.0+ bytes
# lets change the datatypes to perform visualisations
combined_phone_brands_channels_df['Subscribers'] = pd.to_numeric(combined_phone_brands_channels_df['Subscribers'])
combined_phone_brands_channels_df['Views'] = pd.to_numeric(combined_phone_brands_channels_df['Views'])
combined_phone_brands_channels_df['Total_videos'] = pd.to_numeric(combined_phone_brands_channels_df['Total_videos'])
# letsconirm if the datatypes has changed
combined_phone_brands_channels_df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 7 entries, 0 to 6 Data columns (total 4 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Channel_name 7 non-null object 1 Subscribers 7 non-null int64 2 Views 7 non-null int64 3 Total_videos 7 non-null int64 dtypes: int64(3), object(1) memory usage: 356.0+ bytes
combined_phone_brands_channels_df
Channel_name | Subscribers | Views | Total_videos | |
---|---|---|---|---|
0 | Samsung | 6710000 | 1811453473 | 2129 |
1 | Apple | 18700000 | 1187698196 | 191 |
2 | Huawei | 1410000 | 346045185 | 2655 |
3 | Xiaomi | 3010000 | 654368313 | 1462 |
4 | OPPO | 433000 | 127753852 | 458 |
5 | vivo Thailand | 917000 | 819812214 | 325 |
6 | Motorola | 351000 | 6502819 | 190 |
import pandas as pd
import matplotlib.pyplot as plt
# Sort the DataFrame by 'Subscribers' in descending order
combined_phone_brands_channels_df_subscribers_sorted = combined_phone_brands_channels_df.sort_values(by='Subscribers', ascending=False)
# Shorten channel names
combined_phone_brands_channels_df_subscribers_sorted['Channel_name'] = combined_phone_brands_channels_df_subscribers_sorted['Channel_name'].apply(lambda x: x[:8])
# Plotting Subscribers in descending order
fig, axes = plt.subplots(nrows=3, ncols=1, figsize=(10, 15))
axes[0].bar(combined_phone_brands_channels_df_subscribers_sorted['Channel_name'], combined_phone_brands_channels_df_subscribers_sorted['Subscribers'], color='blue')
axes[0].set_title('Subscribers')
# Sort the DataFrame by 'Views' in descending order
combined_phone_brands_channels_df_views_sorted = combined_phone_brands_channels_df.sort_values(by='Views', ascending=False)
# Shorten channel names
combined_phone_brands_channels_df_views_sorted['Channel_name'] = combined_phone_brands_channels_df_views_sorted['Channel_name'].apply(lambda x: x[:8])
# Plotting Views in descending order
axes[1].bar(combined_phone_brands_channels_df_views_sorted['Channel_name'], combined_phone_brands_channels_df_views_sorted['Views'], color='brown')
axes[1].set_title('Views')
# Sort the DataFrame by 'Total_videos' in descending order
combined_phone_brands_channels_df_total_videos_sorted =combined_phone_brands_channels_df.sort_values(by='Total_videos', ascending=False)
# Shorten channel names
combined_phone_brands_channels_df_total_videos_sorted['Channel_name'] = combined_phone_brands_channels_df_total_videos_sorted['Channel_name'].apply(lambda x: x[:8])
# Plotting Total Videos in descending order
axes[2].bar(combined_phone_brands_channels_df_total_videos_sorted['Channel_name'], combined_phone_brands_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()