Today we’re going to show you a visual analysis of a wave of Donald Trump’s tweets, so let’s get started
The development tools
Python version: 3.6.4
And some of the modules that come with Python.
Environment set up
Install Python and add it to the environment variable, and the PIP will install the appropriate module.
First of all, we need to use Panda library to read the Trump Twitter data we downloaded and do some necessary data preprocessing. Specifically, the code implements the following:
Read CSV file
Then we can do some lovely visual analysis with Cutecharts. First, let’s take a look at how many tweets Trump sends each year:
It seems that since he took office in 2017, Donald Trump has been enjoying tweeting more and more. And this 19 years when I was even in the rhythm of Twitter all day long ah (feel the micro business circle of friends are not to do a year like a day to send more than 20 moments of friends T_T).
By the way, the source code of the figure above is as follows, which is quite simple:
Here’s a look at the luxury devices from which Donald Trump tweets (only the top 5 devices are shown) :
Here’s another post on all the tweeting devices he’s used:
Twitter for iPhone 15468
Wow, this one’s pretty well equipped. By the way, the above histogram implementation is similar to the line chart, just need to change the line chart into a bar chart:
chart = Bar(title)
Here’s a look at Trump’s favorite times of day for tweeting:
What an energetic president. T_T
Consider the number of times Donald Trump has mentioned President Barack Obama on Twitter each year since taking office:
It’s the same every year. I can almost imagine the tone of Trump’s tweet about Obama. Cutecharts pie chart code implementation is as follows:
def drawPie(title, data, savedir='results'):
Here’s a quick confirmation of my guess:
Oh, oh, oh, oh, oh, oh, oh, oh, oh, oh, oh, oh. T_T
Let’s take a look at the American media that Donald Trump mentions most on Twitter:
Let’s take a look at Fox at number one:
Without further ado, I would also like to see what Trump says about the media when he tweets. For the sake of the graph, let’s assume that any negative tweet with a score greater than 0.1 is a negative tweet, and any positive tweet with a score greater than 0.2 is a positive tweet:
The scoring is done using Python’s NLTK library, which is not always accurate. By the way, the code to draw radar map is as follows:
Finally, put a word cloud on all of Comrade Trump’s tweets:
After reading this article like friends click like support, pay attention to me every day to share Python data crawler case, the next article will start to enter the simulation login series of QQ space simulation login
All done~ complete source code see personal profile or private message access to related files.