[PYTHON] My dog said, "Make me a star on Youtube!", So I analyzed it with Youtube API.

Nice to meet you. Since I am a beginner in the IT industry, the definition of words may be wrong. If you have any notice, I would appreciate it if you could give me some advice.

In May of this year, I welcomed a dog to my house and started using Youtube to organize the videos I shot. I checked various videos to get started, but as an individual, I noticed ...

――There is an animal-based Youtuber that is so popular that you think "Youtube can make a living?" ――It seems that there is no big relationship between the number of views and the quality of the video. Not expensive)

It was interesting, so I decided to analyze it using the Youtube API.

Analysis target

At home [Welsh Corgi](https://ja.wikipedia.org/wiki/%E3%82%A6%E3%82%A7%E3%83%AB%E3%82%B7%E3%83%A5 % E3% 83% BB% E3% 82% B3% E3% 83% BC% E3% 82% AE% E3% 83% BC) I started to keep a breed of dog.

I want to do analysis related to my Youtube, so I will analyze videos related to Corgi and Youtuber.

Target of this article

This article is written for the following people.

--People who are simply interested in the number of views of videos about Corgi --People who have touched Python and are wondering what you can do with the Youtube API

Simple conclusion

Unfortunately, the Youtube API isn't very versatile, and the content that can be analyzed is very limited. First of all, I will explain "what I was able to do".

What I was able to do

What I was able to do 1

You can use the Search function to search for information on popular videos and channels. For details and code, see Youtube API Reference and Youtube Data API in Python Get Youtube data.

Since we specified q ='Corgi' and order ='viewCount' this time, we succeeded in acquiring the videos that hit the search term Corgi in descending order of the number of views.

** I tried to get 1000 video information, but I couldn't because of the Youtube API specifications. ** ** (950 cases were acquired.) Also, videos that are viewed most often are displayed, but the results change each time you search. When I investigated, there were many videos with less than 100 views in the 900th to 950th. I've posted a video with over 100 views, but it didn't show up, so unfortunately I can't trust the search results too much.

What I was able to do 2

You can use the videos function to specify the videoId and get the video information. For more information, see the Youtube Data API reference here [https://developers.google.com/youtube/v3/docs/videos/list?hl=ja&apix=true#try-it).

In Getting Youtube data with Python using Youtube Data API, you can get the basic information of many videos by the method of "What you can do 1". , The number of views and the number of likes are obtained using the videoId obtained here.

** Note that you cannot specify the channel ID in the videos function. ** ** If you want to get information about all the videos on a channel (such as HIKAKIN), there is no way to get it. ~~ Maybe it's just a lack of ability. .. ~~

What I was able to do 3

You can use the channels function to search for channel information by specifying the Id. See the Youtube Data API reference here [https://developers.google.com/youtube/v3/docs/channels/list?hl=ja) for more information.

We also created a function (below) that allows you to get the total number of views, total likes, etc. of a channel by specifying the channel Id.

#Create a function to get the number of views and likes of the channel by inputting the channelId
def channel_statistics(id):
    statistics = youtube.channels().list(part = 'statistics', id = id).execute()['items'][0]['statistics']
    return statistics

df_static = pd.DataFrame(list(df_channel['channelId'].apply(lambda x : channel_statistics(x))))

df_channel_output = pd.concat([df_channel,df_static], axis = 1)

result of analysis

As mentioned above, the content of the analysis is limited and the results are not robust, but since I have investigated it, I will publish the analysis results as well.

The Corgi market is no longer the only winner of "Corgi Inu Noe-san"

We got 950 information about videos that have been played most often, and compared the top 10 most frequently played channels by video upload year. As a result, until 2018, the situation was divided into groups, but in 2019, "Corgi Inu Noe-san" appeared like a comet, and it can be seen that in 2019 and 2020, it is overwhelmingly different from the second place.

channel_10.png

The total number of views does not increase much just by uploading a lot of videos

I thought, "Mr. Noe, who has an overwhelming difference in 2nd place, is posting the most videos?", And compared the total number of views and the total number of videos posted on the top 10 channels. As a result, "Corgi Inu Noe-san" was the top in the total number of views, but another channel was the top in the total number of video posts.

viewCount_channel.png

videoCount_channel.png

There is a correlation between the number of views and the number of likes, but the number of bad likes is also correlated.

As you might guess, the more videos you play, the more likes you get. The correlation coefficient is 0.87.

like_view.png

What was a little surprising was that as the number of times the video was played, the number of bad likes increased, and the correlation coefficient was 0.82, which is close to the correlation coefficient between the number of likes and the playback function.

dislike_view.png

in conclusion

Corgi dog Noe's Youtube is very interesting with Hokkaido & children & 2 Corgis! By the way, videos are posted almost every day.

Animal-based Youtuber is a tough world. .. ..

* My dog also gave up on becoming a popular Youtuber, saying, "I can't help it. I don't want to work so hard."

Recommended Posts

My dog said, "Make me a star on Youtube!", So I analyzed it with Youtube API.
I tried to make a calculator with Tkinter so I will write it
I made a segment tree with python, so I will introduce it
I tried to make "Sakurai-san" a LINE BOT with API Gateway + Lambda
[Streamlit] I hate JavaScript, so I make a web application only with Python
I was addicted to trying Cython with PyCharm, so make a note
I tried to make a Web API
Make a thermometer with Raspberry Pi and make it visible on the browser Part 3
When I tried to make a VPC with AWS CDK but couldn't make it
I tried to make a castle search API with Elasticsearch + Sudachi + Go + echo
I tried to make a simple image recognition API with Fast API and Tensorflow
I set up TensowFlow and was addicted to it, so make a note
I made my dog "Monaka Bot" with LineBot
I want to make a game with Python
[Python] I made a Youtube Downloader with Tkinter.
I tried to scrape YouTube, but I can use the API, so don't do it.
I have read a survey paper on time-series anomaly detection, so I will summarize it.
A Python beginner made a chat bot, so I tried to summarize how to make it.
I got an error when pip install pandas on Mac, so I dealt with it
It's getting cold, so I tried to make it possible to turn on / off the AC heater automatically with Raspberry Pi!
It took me half a day to install Polyglot in the anaconda environment on my mac, so I'll leave a note