[PYTHON] I tried 200 magical exchanges [Pokemon Sword Shield]

スクリーンショット 2019-12-10 11.51.21.png

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.

The technical story is ...

--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.

Pokemon Sword Shield "Magical Exchange"

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.

I tried it 200 times

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! !! !!

Introducing Python

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. image.png

Summary

This time it was just a Pokemon story. ** Dramesia ** It's a little over one! !!

Recommended Posts

I tried 200 magical exchanges [Pokemon Sword Shield]
I tried scraping
I tried PyQ
I tried AutoKeras
I tried papermill
I tried django-slack
I tried Django
I tried spleeter
I tried cgo
[Pokemon Sword Shield] I tried to visualize the judgment basis of deep learning using the three family classification as an example.
I tried using parameterized
I tried using mimesis
I tried using anytree
I tried competitive programming
I tried running pymc
I tried ARP spoofing
I tried using aiomysql
I tried using Summpy
I tried Python> autopep8
I tried using coturn
I tried using Pipenv
I tried using matplotlib
I tried using "Anvil".
I tried using Hubot
I tried using ESPCN
I tried PyCaret2.0 (pycaret-nightly)
I tried using openpyxl
I analyzed the rank battle data of Pokemon sword shield and visualized it on Tableau
I tried deep learning
I tried AWS CDK!
I tried using Ipython
I tried to debug.
I tried using PyCaret
I tried using cron
I tried Kivy's mapview
I tried using ngrok
I tried using face_recognition
I tried to paste
I tried using Jupyter
I tried using PyCaret
I tried moving EfficientDet
I tried shell programming
I tried using Heapq
I tried using doctest
I tried Python> decorator
I tried running TensorFlow
I tried Auto Gluon
I tried using folium
I tried using jinja2
I tried AWS Iot
I tried Bayesian optimization!
I tried using folium
I tried using time-window