Skip to content

Instantly share code, notes, and snippets.

View SanieRojas's full-sized avatar

Sanie Rojas SanieRojas

  • Argentina
View GitHub Profile
@SanieRojas
SanieRojas / plotting_wallets_dice_rolling.py
Created May 30, 2020 17:24
Plotting histogram of wallets
#Now let´s convert those into balances using the .where function from numpy
np_balances = np.where(np_set_rolls == 5, 10,-5)
np_list_balances= []
for x in np_balances:
np_list_balances.append(sum(x))
#Let´s plot a histogram with the possible economic results of the game
pd_list_balances= pd.Series(np_list_balances)
pd_list_balances.plot.hist(bins=6, cmap="twilight_shifted_r")
@SanieRojas
SanieRojas / wallet_proof_dice_rollings.py
Created May 30, 2020 17:22
Wallet proofing the dice rollings
#Setting a variable for the seed generation
seedgen=3
#Applying the seed function with our variable as a parameter
np.random.seed(seedgen)
#Creating the lists to be populated by the for loops.
rolls= []
set_rolls = []
@SanieRojas
SanieRojas / plot_histogram_dice_rolling.py
Created May 30, 2020 17:19
Plotting an histogram for the dice rollings
list generated in order to manipulate it more easily
df = pd.DataFrame(thousand_scenarios)
df.columns=["Probability"]
df.head(1)
df.plot.hist(bins=10, cmap="plasma")
@SanieRojas
SanieRojas / mean_of_means_dice_rolling.py
Created May 30, 2020 17:17
Thousand scenarios of dice rolling
#Setting a variable for the seed generation
seedgen=1
#Applying the seed function with our variable as a parameter
np.random.seed(seedgen)
#Creating the lists to be populated by the for loops.
fives = []
thousand_scenarios = []
@SanieRojas
SanieRojas / dice_rolling_simulation.py
Created May 30, 2020 17:15
Simulating 5000 dice rollings
#Setting up the seed for the excercise
np.random.seed(123)
#Creating a list to be populated with the amount of fives obtained in 5000 rolls.
fives = []
#Loop to roll the dices 5000 times and append a "1" for each time a 5 is obtained.
for x in range (0,5000):
one_roll = np.random.randint(1,7) + np.random.randint(1,7)
if one_roll == 5:
@SanieRojas
SanieRojas / random_seed.py
Created May 30, 2020 17:13
Generating a seed
np.random.seed(123)
print("Seed 123 gives us: " + str(np.random.randint(0,100)) + " as first result")
print("Seed 123 gives us: " + str(np.random.randint(0,100)) + " as second result")
np.random.seed(1234)
print("Seed 1234 gives us: " + str(np.random.randint(0,100)) + " as first result")
print("Seed 1234 gives us: " + str(np.random.randint(0,100)) + " as second result")
np.random.seed(123)
print("Seed 123 gives us: " + str(np.random.randint(0,100)) + " as first result again")
@SanieRojas
SanieRojas / import_libraries.py
Created May 30, 2020 15:38
import libraries for random walk
import numpy as np
import pandas as pd
from pandas.plotting import bootstrap_plot
@SanieRojas
SanieRojas / plotting_plt_bar_winterfell_deaths_.py
Created May 3, 2020 22:06
plotting_plt_bar:winterfell_deaths
#Creating subset of our dataset, to include only deaths ocurred in Winterfell
data_winterfell = dataset[dataset["Location"].isin(["Winterfell"])].sort_values("Killer")
winterfell_killers = data_winterfell["Killer"].value_counts()
#Setting the x & y axis to the index and values of our "winterfell_killers" series
wfk_index= winterfell_killers.index
wfk_values= winterfell_killers.values
#Plotting the bargraph with some customizations
fig, ax = plt.subplots()
@SanieRojas
SanieRojas / top10_deadliest_houses_got_colored.py
Last active May 3, 2020 21:58
plotting_bar_matplotlib_color
fig, ax = plt.subplots()
data = dataset["Killers House"].value_counts().head(10).index
#splitting the data in two to highlight in a vibrant color only the most important datapoint
data1 = dataset["Killers House"].value_counts().head(1)
data2 = dataset["Killers House"].value_counts().head(10).tail(9) #the only way I could come up with to select the top2-9
x_data1 = data1.index
y_data1 = data1.values
#Creating the plot & setting up the data we´re plotting, in this case, the value count of deaths ocurred per Killers House, as each log represents one death.
fig, ax = plt.subplots()
data = dataset["Killers House"].value_counts().head(10)
#Setting the x & y axis to the index and values of our "data" series
x_data = data.index
y_data = data.values
#Plotting the data itself
ax.bar(x_data , y_data)