"""
![](https://www.unmc.edu/chri/_images/Clinical-Trial-Basics-Diagram.jpg)unmc.edu
"""
# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import seaborn as sns
import matplotlib.pyplot as plt
import plotly.express as px
import plotly.graph_objects as go
import plotly.offline as py
import plotly.express as px

# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory

import os
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        print(os.path.join(dirname, filename))

# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All" 
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
from colorama import Fore, Style

nRowsRead = 1000 # specify 'None' if want to read whole file
# ham_lyrics.csv has 3634 rows in reality, but we are only loading/previewing the first 1000 rows
df = pd.read_csv('../input/covid19-clinical-trials/covid_clinical trials.csv', delimiter=',', nrows = nRowsRead)
df.dataframeName = 'covid19-clinical-trials/covid_clinical trials.csv'
nRow, nCol = df.shape
print(f'There are {nRow} rows and {nCol} columns')
print(Fore.BLUE + 'Data shape: ',Style.RESET_ALL,df.shape)
df.head()
df.isnull().sum()
#Code from Gabriel Preda
#plt.style.use('dark_background')
def plot_count(feature, title, df, size=1):
    f, ax = plt.subplots(1,1, figsize=(4*size,4))
    total = float(len(df))
    g = sns.countplot(df[feature], order = df[feature].value_counts().index[:20], palette= ('#32a852', '#a84e32', '#3242a8'))
    g.set_title("Number and percentage of {}".format(title))
    if(size > 2):
        plt.xticks(rotation=90, size=8)
    for p in ax.patches:
        height = p.get_height()
        ax.text(p.get_x()+p.get_width()/2.,
                height + 3,
                '{:1.2f}%'.format(100*height/total),
                ha="center") 
    plt.show()
plot_count("Sponsor/Collaborators", "Sponsor/Collaborators", df,4)
plot_count("Locations", "Locations", df,4)
plot_count("Acronym", "Acronym", df,4)
plot_count("Status", "Status", df,4)
plot_count("Phases", "Phases", df,4)
plot_count("Funded Bys", "Funded Bys", df,4)
plot_count("Study Type", "Study Type", df,4)
plot_count("Study Designs", "Study Designs", df,4)
plot_count("Study Results", "Study Results", df,4)
"""
#Handling Missing Values
"""
# categorical features with missing values
categorical_nan = [feature for feature in df.columns if df[feature].isna().sum()>0 and df[feature].dtypes=='O']
print(categorical_nan)
# replacing missing values in categorical features
for feature in categorical_nan:
    df[feature] = df[feature].fillna('None')
df[categorical_nan].isna().sum()
# Lets first handle numerical features with nan value
numerical_nan = [feature for feature in df.columns if df[feature].isna().sum()>1 and df[feature].dtypes!='O']
numerical_nan
df[numerical_nan].isna().sum()
## Replacing the numerical Missing Values

for feature in numerical_nan:
    ## We will replace by using median since there are outliers
    median_value=df[feature].median()
    
    df[feature].fillna(median_value,inplace=True)
    
df[numerical_nan].isnull().sum()
#Code by Taha07  https://www.kaggle.com/taha07/data-scientists-jobs-analysis-visualization/notebook

color = plt.cm.RdBu(np.linspace(0,1,20))
df["Phases"].value_counts().sort_values(ascending=False).head(20).plot.pie(y="Status",colors=color,autopct="%0.1f%%")
plt.title("Phases of Clinical Trials")
plt.axis("off")
plt.show()
#Code by Taha07  https://www.kaggle.com/taha07/data-scientists-jobs-analysis-visualization/notebook

color = plt.cm.rainbow(np.linspace(0,1,20))
df["Study Type"].value_counts().sort_values(ascending=False).head(15).plot.pie(y="Status",colors=color,autopct="%0.1f%%")
plt.title("Study Type of Clinical Trials")
plt.axis("off")
plt.show()
#Code by Taha07  https://www.kaggle.com/taha07/data-scientists-jobs-analysis-visualization/notebook

color = plt.cm.Pastel1(np.linspace(0,1,30))
df["Study Designs"].value_counts().sort_values(ascending=False).head(10).plot.pie(y="Status",colors=color,autopct="%0.1f%%")
plt.title("Study Designs of Clinical Trials")
plt.axis("off")
plt.show()
"""
#I couldn't make my Decision Tree neither the Genetic Algorithm. Then I gave up. I'll try another aproach later. 
"""
#Code by Olga Belitskaya https://www.kaggle.com/olgabelitskaya/sequential-data/comments
from IPython.display import display,HTML
c1,c2,f1,f2,fs1,fs2=\
'#eb3434','#eb3446','Akronim','Smokum',30,15
def dhtml(string,fontcolor=c1,font=f1,fontsize=fs1):
    display(HTML("""<style>
    @import 'https://fonts.googleapis.com/css?family="""\
    +font+"""&effect=3d-float';</style>
    <h1 class='font-effect-3d-float' style='font-family:"""+\
    font+"""; color:"""+fontcolor+"""; font-size:"""+\
    str(fontsize)+"""px;'>%s</h1>"""%string))
    
    
dhtml('Marília Prata, @mpwolke ist hier' )