<jupyter_start><jupyter_text>Fig11. Distribution of projects according to funding received.  Import libraries<jupyter_code>import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import numpy as np
import pandas as pd
import matplotlib as mpl

plt.style.use('seaborn-muted')

def read_csv(path):
    """
    :param path: of desir the xlsx file
    :return: String that contains all project descriptions
    """
    df = pd.read_csv(path)
    filtered_df = df.replace(np.nan, 0, regex=True)
    
    
    return filtered_df<jupyter_output><empty_output><jupyter_text>Define projects data path<jupyter_code>file_path = "../data/mapeo_proyectos.csv"<jupyter_output><empty_output><jupyter_text>Define function to clean projects data<jupyter_code>def prepare_data(data):
    data.drop_duplicates(subset ="ID proyecto", keep = "first", inplace = True)
    data["Financiación"] = pd.to_numeric(data["Financiación"], errors='coerce')
    data = data[data["Financiación"] != 0]
    mini = data[["ID proyecto","Financiación"]]
    # mini = mini.groupby(['ID proyecto'])["Financiación"].apply(list).reset_index(name='Financiación')
    # new_fins = [fin[0] for fin in mini["Financiación"]]
    # mini["Financiación"] = new_fins
    mini = mini.drop(["ID proyecto"], axis=1)
    grp = mini.groupby(pd.cut(mini["Financiación"], np.arange(1, 10+mini['Financiación'].max(), 10000))).agg({'Financiación':['count']})
    
    grp["pcts"] = grp.apply(lambda x:100 * x / float(x.sum()))
    grp['cum_sum'] = grp['pcts'].cumsum()
    grp.reset_index(level=[0], inplace=True)
    grp.columns = grp.columns.droplevel(1)
    grp.columns = ["rango","count","pcts","pcts_sum"]
    grp["rango"] = grp.rango.apply(lambda x: x.right - 1.0)
    df1 = grp.iloc[:25]
    more_df = grp.iloc[25:]
    more_df = more_df[more_df["count"] > 0]
    more_pcts = grp.loc[grp['pcts_sum'] > grp.iloc[25, 3], "pcts"].sum()
    more_count = more_df["count"].sum()
    result = df1.append({'rango' : 'More',
                      'count': more_count,
                      'pcts' : more_pcts,
                      'pcts_sum': 100
                    } , ignore_index=True)   
    return result<jupyter_output><empty_output><jupyter_text>Run program<jupyter_code>proyectos = read_csv(file_path)
df2 = prepare_data(proyectos)<jupyter_output><empty_output><jupyter_text>Print graph<jupyter_code>plt.figure()
ax1 = df2[['rango', 'count']].plot(x='rango', kind="bar", figsize=(16,9), legend=False, width=0.4, color="grey")
ax1.set_ylabel("# of projects")
ax2 = df2['pcts_sum'].plot(secondary_y=True, marker='o')
ax2.set_ylim(bottom=0)
ax2.yaxis.set_major_formatter(ticker.PercentFormatter(decimals=0))
ax2.yaxis.set_major_locator(ticker.MultipleLocator(10.00))
plt.setp(ax1.xaxis.get_majorticklabels(), rotation=60, ha="right")
# plt.title("Number of research projects and total funding across the whole analysed period (1993-2019)",fontsize=20,fontweight="bold")
ax1.grid(axis="y")
#ax2.grid(axis="y")
plt.show()<jupyter_output><empty_output><jupyter_text>Table<jupyter_code>df2<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1611328125, 'fraction_numerical': 0.022786458333333332, 'mean_word_length': 4.9096153846153845, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 27, 'https://': 0, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '31380', 'license': 'Apache-2.0', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1166, 'n_words': 185, 'path': 'notebooks/11. Distribution of projects according to funding received.ipynb', 'repo_name': 'linhd-postdata/desir', 'size': '3072'}