Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- plt.style.use("ggplot")
- plt.figure(figsize=(12, 8))
- plt.bar(df_converted['Year'], df_converted['Dividends'], color = 'b')
- # Set x-axis ticks to display every year between 1 and rotate them
- plt.xticks(np.arange(df_converted['Year'].min(), df_converted['Year'].max() + 1, 1), rotation=45)
- plt.xlabel('Year')
- plt.ylabel('Total Dividends')
- plt.title('Dividends by Year')
- # Show grid and plot
- plt.grid(True)
- plt.show()
- ########################################################################################################3
- age_bins = [0, 10, 18, 30, 55, 100]
- cats = pd.cut(titanic.age, age_bins, right = False)
- titanic["age_cat"] = cats
- titanic.groupby("age_cat").survived.mean()
- group_names = ["child", "teenager", "young_adult", "adult", "elderly"]
- titanic["age_cat"] = pd.cut(titanic.age, age_bins, right = False, labels = group_names)
- ########################################################################################
- titanic["fare_cat"] = pd.cut(titanic.fare, 5, precision= 0)
- titanic.fare_cat.value_counts()
- ########################################################################################
- titanic["fare_cat"] = pd.qcut(titanic.fare, 5)
- fare_labels =["very_cheap", "cheap", "moderate", "exp", "very_exp"]
- titanic["fare_cat"] = pd.qcut(titanic.fare, [0, 0.1, 0.25, 0.5, 0.9, 1], precision = 0, labels = fare_labels)
- titanic.fare_cat.value_counts()
- titanic.groupby(["age_cat", "fare_cat"]).survived.mean().unstack()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement