<jupyter_start><jupyter_text>Import Data<jupyter_code>df = pd.read_csv(
    "./data/investments_VC.csv", 
    encoding= "ISO-8859-1",
    parse_dates= ["founded_at", "first_funding_at", "last_funding_at"],
)
df.head()<jupyter_output><empty_output><jupyter_text>EDA Basic Info<jupyter_code>df.info(verbose=True, memory_usage="deep")<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 54294 entries, 0 to 54293
Data columns (total 39 columns):
permalink               49438 non-null object
name                    49437 non-null object
homepage_url            45989 non-null object
category_list           45477 non-null object
 market                 45470 non-null object
 funding_total_usd      49438 non-null object
status                  48124 non-null object
country_code            44165 non-null object
state_code              30161 non-null object
region                  44165 non-null object
city                    43322 non-null object
funding_rounds          49438 non-null float64
founded_at              54294 non-null object
founded_month           38482 non-null object
founded_quarter         38482 non-null object
founded_year            38482 non-null float64
first_funding_at        54294 non-null object
last_funding_at         54294 non-null object
seed                    49438 non-null float64
venture       [...]<jupyter_text>Missing Value Info<jupyter_code>plot_missing_value(df)
(df.isna().sum() / len(df)) * 100<jupyter_output><empty_output><jupyter_text>Fixed Weird Rows / Cols name<jupyter_code>def convert_str2float(fund: str) -> float:
    try:
        return float("".join(re.findall("\d+", fund)))
    except:
        return np.nan

df["market"] = df[" market "]
df["funding_total_usd"] = df[" funding_total_usd "]

df["funding_total_usd"] = df["funding_total_usd"].apply(lambda x: convert_str2float(x))
df.dropna(subset= [" funding_total_usd "], inplace=True)
df.drop(columns=[" market ", " funding_total_usd "], inplace=True)<jupyter_output><empty_output><jupyter_text>Popular Market & Country<jupyter_code># Prepare Data
df_raw = df.copy()

df_raw = df_raw[df_raw["market"].isin(dict(df_raw.market.value_counts()[:11]).keys())]
df_raw = df_raw[['funding_total_usd', 'market']].groupby('market').apply(lambda x: x.mean())
df_raw.sort_values('funding_total_usd', inplace=True)
df_raw.reset_index(inplace=True)

min_fund = df_raw.funding_total_usd.min()
max_fund = df_raw.funding_total_usd.max()

# # Draw plot
fig, ax = plt.subplots(figsize=(10,8), dpi= 80)
ax.hlines(y=df_raw.index, xmin=min_fund - 1000000, xmax=max_fund + 1500000, color='gray', alpha=0.7, linewidth=1, linestyles='dashdot')
ax.scatter(
    y=df_raw.index, 
    x=df_raw.funding_total_usd, 
    s=75, 
    color='firebrick', 
    alpha=0.7
)

# # Title, Label, Ticks and Ylim
ax.set_title('Average Funding per Market Start Up', fontdict={'size':22})
ax.set_xlabel('USD')
ax.set_yticks(df_raw.index)
ax.set_yticklabels(df_raw.market.str.title(), fontdict={'horizontalalignment': 'right'})
ax.set_xlim(min_fund - 2000000, max_fund + 2500000);
market_count  = df['market'].value_counts()
market_count = market_count[:10,]

market_plot = sns.barplot(
    market_count.index, 
    market_count.values, 
    alpha=0.8,
)

for item in market_plot.get_xticklabels():
    item.set_rotation(-90)
    
plt.title('Top 10 Market in Start Up Investments')
plt.ylabel('Total Companies', fontsize=12)
plt.xlabel('Market Type', fontsize=12)
plt.show()
country_count  = df['country_code'].value_counts()
country_count = country_count[:10,]

country_plot = sns.barplot(
    country_count.index, 
    country_count.values, 
    alpha=0.8,
)
    
plt.title('Top 10 Countries in Start Up Investments')
plt.ylabel('Total Companies', fontsize=12)
plt.xlabel('Countries', fontsize=12)
plt.show()
status_count  = df['status'].value_counts()
status_count = status_count[:10,]

status_plot = sns.barplot(
    status_count.index, 
    status_count.values, 
    alpha=0.8,
)
    
plt.title('Status in Start Up Investments')
plt.ylabel('Total Companies', fontsize=12)
plt.xlabel('Status', fontsize=12)
plt.show()
backup = df.copy()
df_raw = backup.copy()
df_raw.founded_year.max()
df_raw = df.copy()
top_categories = list(dict(df_raw.market.value_counts()[:5]).keys())
df_raw = df_raw[df_raw["market"].isin(top_categories)]

def get_founded_year_cat(year):
    if year < 2000:
        return "1900s"
    elif year < 2010:
        return "2000s"
    elif year >= 2010:
        return "2010s"

df_raw["founded_year_cat"] = df_raw.founded_year.apply(lambda x: get_founded_year_cat(x))
df_raw.dropna(subset=["founded_year_cat"], inplace=True)
df_raw = df_raw[['founded_year_cat', "market"]].groupby(['market', 'founded_year_cat']).size()
df_raw = df_raw.unstack()
df_raw
a
import matplotlib.lines as mlines
# Import Data

klass1 = ['red' if (y1-y2) < 0 else 'green' for y1, y2 in zip(df_raw['1900s'], df_raw['2000s'])]
klass2 = ['red' if (y1-y2) < 0 else 'green' for y1, y2 in zip(df_raw['2000s'], df_raw['2010s'])]

# draw line
# https://stackoverflow.com/questions/36470343/how-to-draw-a-line-with-matplotlib/36479941
def newline(p1, p2, color='black'):
    ax = plt.gca()
    l = mlines.Line2D([p1[0],p2[0]], [p1[1],p2[1]], color='red' if p1[1]-p2[1] > 0 else 'green', marker='o', markersize=6)
    ax.add_line(l)
    return l

fig, ax = plt.subplots(1,1,figsize=(14,14), dpi= 80)

# Vertical Lines
ax.vlines(x=1, ymin=50, ymax=1900, color='black', alpha=0.7, linewidth=1, linestyles='dotted')
ax.vlines(x=3, ymin=50, ymax=1900, color='black', alpha=0.7, linewidth=1, linestyles='dotted')
ax.vlines(x=5, ymin=50, ymax=1900, color='black', alpha=0.7, linewidth=1, linestyles='dotted')

# # Points
ax.scatter(y=df_raw['1900s'], x=np.repeat(1, df_raw.shape[0]), s=10, color='black', alpha=0.7)
ax.scatter(y=df_raw['2000s'], x=np.repeat(3, df_raw.shape[0]), s=10, color='black', alpha=0.7)
ax.scatter(y=df_raw['2010s'], x=np.repeat(5, df_raw.shape[0]), s=10, color='black', alpha=0.7)

# # Line Segmentsand Annotation
for p1, p2, p3, c in zip(df_raw['1900s'], df_raw['2000s'], df_raw['2010s'], df_raw.index):
    newline([1, p1], [3, p2])
    newline([3, p2], [5, p3])
    ax.text(1+0.05, p1, c , horizontalalignment='right', verticalalignment='center', fontdict={'size':14})
    ax.text(3+0.05, p2, c , horizontalalignment='right', verticalalignment='center', fontdict={'size':14})
    ax.text(5+0.05, p3, c , horizontalalignment='left', verticalalignment='center', fontdict={'size':14})

# # 'Before' and 'After' Annotations
ax.text(1+0.05, 1900, '1900s', horizontalalignment='left', verticalalignment='center', fontdict={'size':18, 'weight':700})
ax.text(3+0.05, 1900, '2000s', horizontalalignment='left', verticalalignment='center', fontdict={'size':18, 'weight':700})
ax.text(5+0.05, 1900, '2010s', horizontalalignment='left', verticalalignment='center', fontdict={'size':18, 'weight':700})

# # Decoration
ax.set_title("Comparing Total Investment Start Up between 1900s, 2000s, and 2010s", fontdict={'size':22})
ax.set(xlim=(0, 6), ylim=(0, 2000), ylabel='Total Companies')
ax.set_ylabel('Total Companies', fontdict={'size':22})
ax.set_xticks([1, 3, 5])
ax.set_xticklabels(["1900s", "2000s", "2010s"])
plt.yticks(np.arange(0, 2000, 200), fontsize=12)

# # Lighten borders
plt.gca().spines["top"].set_alpha(.0)
plt.gca().spines["bottom"].set_alpha(.0)
plt.gca().spines["right"].set_alpha(.0)
plt.gca().spines["left"].set_alpha(.0)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16541353383458646, 'fraction_numerical': 0.06699785177228786, 'mean_word_length': 4.911904761904762, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 24, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '12849', 'license': 'MIT', 'n_tokens_mistral': 3135, 'n_tokens_neox': 2783, 'n_words': 518, 'path': 'Start Up Investments.ipynb', 'repo_name': 'Eunha-Personal-Assistant/EDA-StartUpInvestments', 'size': '7448'}