Money cant buy happiness but it can buy beer

  1. Home
  2. Decor
  3. Wall Decor
  4. Shop All Wall Decor

The Lizton Sign Shop

$25.95

$25.95

Item not available with current selections

How do you want your item?

Money cant buy happiness but it can buy beer

Notice unusual marketplace activity?

Report

Introduction to Data Analytics with Python

Photo by Adam Wilson on Unsplash

We have all heard the saying “Money cannot buy you happiness,” but what factors lead a person to a life of happiness? Like many questions in this world, the answers can be found by analyzing data.

But where can you begin?

  1. Finding a dataset — For this project, I found a dataset on Kaggle titled Happiness and Alcohol Consumption. It gives units and descriptions for the columns. Kaggle has public datasets and resources to help get you started.
  2. Install and import your libraries — Here is the Pandas and MatPlotLib documentation to set up your notebook.
import pandas as pd
import matplotlib.pyplot as plt

3. Read in, clean, and prepare the dataset — This line of code and taking the CSV file and converting it to a Pandas DataFrame.It is important to look for outliers, missing values, duplicates, etc.

df = pd.read_csv('HappinessAlcoholConsumption.csv')

If we take a look at the dataframe we get 122 rows and 9 columns. To look into datatypes and null values, you can run df.info().

Money cant buy happiness but it can buy beer

4. Data Analysis

In Pandas, the columns are called Series. To view the entire column, we can use: df[‘column_name’]. To look at the counts of the data in a series, we can add .value_counts() to the end of the column selection.

For example, if we want to look at the number of countries we have in each region, we can use:

df['Region'].value_counts()

Money cant buy happiness but it can buy beer

You can create new columns using the others! For example, if we wanted to add the beer, wine, and spirit per capita to get a total, we can run the following line of code. This method is called broadcasting.

df['total_PerCapita'] = df['Beer_PerCapita'] + df['Spirit_PerCapita'] + df['Wine_PerCapita']

We can look for specific items in the dataset using the following method:

df[df['Country'] == 'United States']
# this will select the row with the USA's data
df[df['HappinessScore'] >= 6]
# this will return rows with a happiness score above 6

To take a look at the distribution of the numerical columns, we can using the method describe. This can help you gain insight on the data you are working with.

df.describe()

Money cant buy happiness but it can buy beer

To look at the correlation between the columns, we can use the following:

df.corr()

Let create some visualizations using Matplotlib!

Visualization is a very powerful tool when it come to data analytics. One of the most common python libraries data scientist use is Matplotlib. With this library, we can create bar charts, scatterplots, boxplots, pie charts, histograms, and more! To customize your visualizations, use this reference for color names.

To start, we can look at the data using histograms. We can use the .hist() method to get a histogram for each numerical column in the dataset.

df.hist(figsize=(20,15), color='cornflowerblue');
# figsize is specifying the height and width of the histograms

Money cant buy happiness but it can buy beer

A Bar Chart is created by using .bar(x, y) or .barh(x, y), depending on if you want a vertical or horizontal bar chart.

# Set x and y data
y = df3.groupby(['Region'])['total_PerCapita'].mean().sort_values()
x = y.index
figure, ax = plt.subplots(figsize = (10,5))# Set Labels
ax.set_title('Average Consumption Per Capita by Region', fontsize=12)
ax.set_xlabel('Average Consumption Per Capita', fontsize=12)
ax.set_ylabel('Region', fontsize=12)
# Plot
ax.barh(x, y, color='peachpuff');

Money cant buy happiness but it can buy beer

5. Draw Insights — use visualization, statistics, and more.

The correlation between Happiness Score and Beer Consumption per Capita is 0.5, meaning it is low positive correlation (found using the df.corr() method above!!) .

Money cant buy happiness but it can buy beer

Below is the data with happiness and alcohol consumption grouped by each region. This data is used to create the heat maps below.

Money cant buy happiness but it can buy beer

Money cant buy happiness but it can buy beer

Money cant buy happiness but it can buy beer

In conclusion, alcohol consumption is correlated with a country’s happiness score — BUT CORRELATION DOES NOT MEAN CAUSATION!!

It is important in data science projects to take everything with a grain of salt. For this data set, we don’t know if it was a random sample of participants from each country. People can be dishonest when reporting how happy they are or how much alcohol they consume. Happiness is a challenging concept to assign a number to. Thinking about the bias in the data when beginning a project.

And with those steps, you are getting a hang of the basics! The best way to learn how to code is tho learn how to be resourceful!! Use online examples, watch videos, and more. The material is endless for you to be successful.

Thank you for reading — Cheers!

Gain Access to Expert View — Subscribe to DDI Intel