This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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 = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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 = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import pandas as pd | |
| from pandas.plotting import bootstrap_plot |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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) |
NewerOlder