In [1]:
# Import
import pandas as pd
import seaborn as sns
import numpy as np

import matplotlib
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
plt.style.use('ggplot')
from matplotlib.pyplot import figure

%matplotlib inline
matplotlib.rcParams['figure.figsize'] = (12,8)


# Import data

df=pd.read_csv(r"\kickstarter_projects.csv")

#Add custom color palette for statuses
category_hues = {
    'Failed': 'r',
    'Successful': 'g',
    'Canceled': 'b',
    'Suspended': 'm',
    'Live': 'y'
}
In [2]:
#Get year range
df['Launched']=pd.to_datetime(df['Launched'])
max_year=df['Launched'].max().year 
min_year=df['Launched'].min().year 

#Set colors and style
sns.set_theme(style="whitegrid")
sns.set_color_codes("muted")

#Create plot
sns.catplot(data=df, x='Category', hue="State", kind="count", height=12, aspect=2, legend_out=False, palette=category_hues) 
plt.legend(title='Status') 
plt.xlabel('Category') 
plt.ylabel('Campaigns') 
plt.title('Kickstarter Status by Category between '+str(min_year)+'–'+str(max_year))
Out[2]:
Text(0.5, 1.0, 'Kickstarter Status by Category between 2009–2018')
In [3]:
#Set style and plot size
sns.set_theme(style="whitegrid")
f, ax = plt.subplots(figsize=(20, 8))
sns.set_color_codes("muted")


#Group data by category and state in respect to total goal amount.
total_goal = df.groupby(['Category', 'State'])['Goal'].sum().reset_index()
total_pledged = df.groupby(['Category', 'State'])['Pledged'].sum().reset_index()

#Plot total goal amount
sns.barplot(data=total_goal, y='Category', x='Goal', ci=None, color="r", label="Goal") 

#Plot and overlap total pledged amount.
sns.barplot(data=total_pledged, y='Category', x='Pledged', ci=None, color="g", label="Pledged") 
sns.despine(left=True, bottom=True)



#Display legend
ax.legend(ncol=2, loc="lower right", frameon=True)

#Format goal amount to read as dollars in the thousands, millions, and billions notations.
def currency_formatter(x, pos):
    """Format tick label as dollar amount"""
    if x >= 1e9:
        value = x / 1e9
        suffix = 'B'
    elif x >= 1e6:
        value = x / 1e6
        suffix = 'M'
    else:
        value = x / 1e3
        suffix = 'K'
    return f'${value:.1f}{suffix}'

#Add labels to the graph
plt.ylabel('Category') 
plt.xlabel('Pledged and Goal') 
ax.xaxis.set_major_formatter(ticker.FuncFormatter(currency_formatter))
plt.title('Total Kickstarter Goal and Pledged Amount by Category between '+str(min_year)+'–'+str(max_year))
plt.show()
In [4]:
#Set style
sns.set_color_codes("muted")
sns.set_palette(['b', 'r', 'y','g','m'])

# Get unique categories
categories = df['Category'].unique()
num_categories = len(categories)

# Set rows and columns
num_rows = 5
num_cols = 3

# Create subplots for each category
fig, axes = plt.subplots(nrows=num_rows, ncols=num_cols, figsize=(30, 50))


for i, category in enumerate(categories):

    # Calculate the position in the grid
    row = i // num_cols
    col = i % num_cols
    
    # Filter DataFrame for the current category
    category_df = df[df['Category'] == category]
    
    # Calculate the count of unique states in the filtered DataFrame
    state_counts = category_df['State'].value_counts()
    state_counts_sorted = state_counts.sort_index()
    # Extract the data for the pie chart
    labels = state_counts_sorted.index
    sizes = state_counts_sorted.values
    
    # Create the pie chart
    wedges, _ = axes[row, col].pie(sizes, labels=['']* len(labels))
    axes[row, col].axis('equal')
    axes[row, col].set_title(category+" (Campaign Count)", fontsize=30)
    
    axes[row, col].legend(wedges, labels, loc='center left', bbox_to_anchor=(1, 0.5), fontsize=25)



    
plt.tight_layout()
# Display the charts

plt.show()
In [5]:
# Get unique categories
categories = df['Category'].unique()
num_categories = len(categories)

# Set rows and columns
num_rows = 5
num_cols = 3

# Create subplots for each category
fig, axes = plt.subplots(nrows=num_rows, ncols=num_cols, figsize=(30, 50))
plt.rcParams['font.size'] = 15    


for i, category in enumerate(categories):
    # Calculate the position in the grid
    row = i // num_cols
    col = i % num_cols
    
    # Filter DataFrame for the current category
    category_df = df[df['Category'] == category]
    
    # Calculate the count of unique states in the filtered DataFrame
    state_counts = category_df.groupby('State')['Goal'].sum()
    state_counts_sorted = state_counts.sort_index()
    # Extract the data for the pie chart
    labels = state_counts_sorted.index
    sizes = state_counts_sorted.values
    
    # Create the pie chart
    wedges, _ = axes[row, col].pie(sizes, labels=['']* len(labels))
    axes[row, col].axis('equal')
    axes[row, col].set_title(category+" (Total Goal Amount)", fontsize=30)
    
    axes[row, col].legend(wedges, labels, loc='center left', bbox_to_anchor=(1, 0.5), fontsize=25)
    
plt.tight_layout()
# Display the charts
plt.show()
In [ ]: