Yes, thankyou. I'm too addicted to the Pokemon sword shield and my research doesn't proceed. My name is Dason. Thank you.
By the way, in the Department of Phenomenon and Mathematical Sciences that I graduated from, there is a student-originated academic year exchange LT "#MS_NCLT" (or rather, we made it). So, I announced this year, but behind that there was a good subject to learn the basic tabulation of Python, so I think I'll summarize it in Qiita.
--Easy aggregation with pandas --Draw a bar graph with diagonal horizontal axis labels in matplotlib --Using Japanese with matplotlib
Will be. I only use it because it's easy.
If you've played Pokemon, you're familiar with it, magical exchange. (Until recently, I thought it was a "miracle exchange". Arora!)
It is a function that randomly connects to someone in the world and exchanges Pokemon with that person only once.
It's good and scary not to know what's coming from the other party.
The Pokemon that flows into the magical exchange Unnecessary Pokemon or hatching carefully selected Pokemon Will be.
The experiment date is November 30th. Only two weeks have passed since its release It is a time when so-called "gachis" are carefully selecting for hatching, and it is also a period when many good individuals flow.
In other words ** If you look at the Pokemon that flow into the magical exchange at this time Do you know the strong or popular Pokemon of this work? ** ** I thought.
So, 200 times. After exchanging, make a note of the Pokemon that came to you. While writing the thesis abstract 3 days before the deadline and writing the report 5 days before the deadline Approximately 8 hours. I worked hard.
Now, let's count! !! !!
I named the file that recorded 200 exchanges NCLT_pokemon.csv
. Here, the Pokemon that came to hand in order from the top are listed.
I will read this with python and aggregate it. First, declare the package to use.
import numpy as np
import pandas as pd
import collections
import matplotlib.pyplot as plt
%matplotlib inline
Then load csv.
df = pd.read_csv('NCLT_pokemon.csv')
Let's take a look at the contents of the data.
#Three are randomly extracted from the data frame df.
df.sample(3)
Pokemon | |
---|---|
21 | Roselia |
10 | Belobar |
89 | Machop |
Like this.
Now, let's count how many times each Pokemon has come to hand. If you use Counter in collections, it will count in an instant.
c = collections.Counter(np.array(df['Pokemon']))
This c
already contains the aggregated results.
However, it is very hard to see as it is, so let's shape it with pandas.
#Since Counter is a dictionary, convert it to DataFrame.
num_poke = pd.DataFrame.from_dict(c, orient='index')
#In addition, specify the column name
num_poke.columns = ['Number of appearances']
#Sort by the number of occurrences.
num_poke_sort = num_poke.sort_values('Number of appearances', ascending=False)
This completes the shaping. Let's take a look at Top5!
num_poke_sort.head(5)
Number of appearances | |
---|---|
Dramesia | 12 |
Magikarp | 9 |
Mimikyu | 6 |
Scorbunny | 6 |
Galal Ponita | 5 |
So, the result of 200 times ** Dramesia ** was number one in 12 times! The new 600 family is strong, isn't it?
Let's plot at the end.
Since the name of Pokemon is in Japanese, use the library japanize-matplotlib
that makes matplotlib compatible with Japanese. Installation is
pip install japanize-matplotlib
You can do it from. Now let's draw.
import matplotlib.pyplot as plt
import japanize_matplotlib
#Specify the screen size of the figure
plt.figure(figsize=(30,5))
#Draw bar chart
plt.bar(np.array(num_poke_sort.index), num_poke_sort['Number of appearances'])
#Rotate the label on the horizontal axis 70 degrees for easy viewing
plt.xticks(rotation=70)
It's done.
This time it was just a Pokemon story. ** Dramesia ** It's a little over one! !!
Recommended Posts