import pandas as pd
import numpy as np


#CLEAN DATA:
def clean_data(df):
    col_drop=["Indicator Name","Indicator Code"]
    count_drop=[
        "Arab World",
        "Central Europe and the Baltics",
        "Caribbean small states",
        "East Asia & Pacific (excluding high income)",
        "Early-demographic dividend",
        'East Asia & Pacific',
        'Europe & Central Asia (excluding high income)',
        'Europe & Central Asia',
        'Euro area',
        'European Union',
        'Fragile and conflict affected situations',
        'High income',
        'Heavily indebted poor countries (HIPC)',
        'IBRD only',
        'IDA & IBRD total',
        'IDA total',
        'IDA blend',
        'IDA only',
        'Not classified',
        'Latin America & Caribbean (excluding high income)',
        'Latin America & Caribbean',
        'Least developed countries: UN classification',
        'Low income',
        'Lower middle income',
        'Low & middle income',
        'Late-demographic dividend',
        'Middle East & North Africa',
        'Middle income',
        'Middle East & North Africa (excluding high income)',
        'North America',
        'OECD members',
        'Other small states',
        'Pre-demographic dividend',
        'West Bank and Gaza',
        'Pacific island small states',
        'Post-demographic dividend',
        'South Asia',
        'Sub-Saharan Africa (excluding high income)',
        'Sub-Saharan Africa',
        'Small states',
        'East Asia & Pacific (IDA & IBRD countries)',
        'Europe & Central Asia (IDA & IBRD countries)',
        'Latin America & the Caribbean (IDA & IBRD countries)',
        'Middle East & North Africa (IDA & IBRD countries)',
        'South Asia (IDA & IBRD)',
        'Sub-Saharan Africa (IDA & IBRD countries)',
        'Upper middle income','World']
    cdf=df.copy()
    cdf=cdf.drop(col_drop, axis=1)
    bad_countries=cdf[cdf["Country Name"].isin(count_drop)==True].index
    cdf=cdf.drop(bad_countries,axis=0)
    cdf["Country Name"] = cdf["Country Name"].apply(lambda x: " ".join(x.split(",")[::-1]) if x in ["Congo, Dem. Rep.","Congo, Rep.","Korea, Rep.","Korea, Dem. People’s Rep."] else x)
    cdf["Country Name"] = cdf["Country Name"].apply(lambda x: x.split(",")[0])
    cdf=cdf.fillna(0)
    cdf["Country Name"] = cdf["Country Name"].apply(lambda x: x.upper().strip())
    return cdf

COUNTRIES=['ARUBA',
 'AFGHANISTAN',
 'ANGOLA',
 'ALBANIA',
 'ANDORRA',
 'UNITED ARAB EMIRATES',
 'ARGENTINA',
 'ARMENIA',
 'AMERICAN SAMOA',
 'ANTIGUA AND BARBUDA',
 'AUSTRALIA',
 'AUSTRIA',
 'AZERBAIJAN',
 'BURUNDI',
 'BELGIUM',
 'BENIN',
 'BURKINA FASO',
 'BANGLADESH',
 'BULGARIA',
 'BAHRAIN',
 'BAHAMAS',
 'BOSNIA AND HERZEGOVINA',
 'BELARUS',
 'BELIZE',
 'BERMUDA',
 'BOLIVIA',
 'BRAZIL',
 'BARBADOS',
 'BRUNEI DARUSSALAM',
 'BHUTAN',
 'BOTSWANA',
 'CENTRAL AFRICAN REPUBLIC',
 'CANADA',
 'SWITZERLAND',
 'CHANNEL ISLANDS',
 'CHILE',
 'CHINA',
 "COTE D'IVOIRE",
 'CAMEROON',
 'DEM. REP. CONGO',
 'REP. CONGO',
 'COLOMBIA',
 'COMOROS',
 'CABO VERDE',
 'COSTA RICA',
 'CUBA',
 'CURACAO',
 'CAYMAN ISLANDS',
 'CYPRUS',
 'CZECH REPUBLIC',
 'GERMANY',
 'DJIBOUTI',
 'DOMINICA',
 'DENMARK',
 'DOMINICAN REPUBLIC',
 'ALGERIA',
 'ECUADOR',
 'EGYPT',
 'ERITREA',
 'SPAIN',
 'ESTONIA',
 'ETHIOPIA',
 'FINLAND',
 'FIJI',
 'FRANCE',
 'FAROE ISLANDS',
 'MICRONESIA',
 'GABON',
 'UNITED KINGDOM',
 'GEORGIA',
 'GHANA',
 'GIBRALTAR',
 'GUINEA',
 'GAMBIA',
 'GUINEA-BISSAU',
 'EQUATORIAL GUINEA',
 'GREECE',
 'GRENADA',
 'GREENLAND',
 'GUATEMALA',
 'GUAM',
 'GUYANA',
 'HONG KONG SAR',
 'HONDURAS',
 'CROATIA',
 'HAITI',
 'HUNGARY',
 'INDONESIA',
 'ISLE OF MAN',
 'INDIA',
 'IRELAND',
 'IRAN',
 'IRAQ',
 'ICELAND',
 'ISRAEL',
 'ITALY',
 'JAMAICA',
 'JORDAN',
 'JAPAN',
 'KAZAKHSTAN',
 'KENYA',
 'KYRGYZ REPUBLIC',
 'CAMBODIA',
 'KIRIBATI',
 'ST. KITTS AND NEVIS',
 'REP. KOREA',
 'KUWAIT',
 'LAO PDR',
 'LEBANON',
 'LIBERIA',
 'LIBYA',
 'ST. LUCIA',
 'LIECHTENSTEIN',
 'SRI LANKA',
 'LESOTHO',
 'LITHUANIA',
 'LUXEMBOURG',
 'LATVIA',
 'MACAO SAR',
 'ST. MARTIN (FRENCH PART)',
 'MOROCCO',
 'MONACO',
 'MOLDOVA',
 'MADAGASCAR',
 'MALDIVES',
 'MEXICO',
 'MARSHALL ISLANDS',
 'MACEDONIA',
 'MALI',
 'MALTA',
 'MYANMAR',
 'MONTENEGRO',
 'MONGOLIA',
 'NORTHERN MARIANA ISLANDS',
 'MOZAMBIQUE',
 'MAURITANIA',
 'MAURITIUS',
 'MALAWI',
 'MALAYSIA',
 'NAMIBIA',
 'NEW CALEDONIA',
 'NIGER',
 'NIGERIA',
 'NICARAGUA',
 'NETHERLANDS',
 'NORWAY',
 'NEPAL',
 'NAURU',
 'NEW ZEALAND',
 'OMAN',
 'PAKISTAN',
 'PANAMA',
 'PERU',
 'PHILIPPINES',
 'PALAU',
 'PAPUA NEW GUINEA',
 'POLAND',
 'PUERTO RICO',
 'DEM. PEOPLE’S REP. KOREA',
 'PORTUGAL',
 'PARAGUAY',
 'FRENCH POLYNESIA',
 'QATAR',
 'ROMANIA',
 'RUSSIAN FEDERATION',
 'RWANDA',
 'SAUDI ARABIA',
 'SUDAN',
 'SENEGAL',
 'SINGAPORE',
 'SOLOMON ISLANDS',
 'SIERRA LEONE',
 'EL SALVADOR',
 'SAN MARINO',
 'SOMALIA',
 'SERBIA',
 'SOUTH SUDAN',
 'SAO TOME AND PRINCIPE',
 'SURINAME',
 'SLOVAK REPUBLIC',
 'SLOVENIA',
 'SWEDEN',
 'SWAZILAND',
 'SINT MAARTEN (DUTCH PART)',
 'SEYCHELLES',
 'SYRIAN ARAB REPUBLIC',
 'TURKS AND CAICOS ISLANDS',
 'CHAD',
 'TOGO',
 'THAILAND',
 'TAJIKISTAN',
 'TURKMENISTAN',
 'TIMOR-LESTE',
 'TONGA',
 'TRINIDAD AND TOBAGO',
 'TUNISIA',
 'TURKEY',
 'TUVALU',
 'TANZANIA',
 'UGANDA',
 'UKRAINE',
 'URUGUAY',
 'UNITED STATES',
 'UZBEKISTAN',
 'ST. VINCENT AND THE GRENADINES',
 'VENEZUELA',
 'BRITISH VIRGIN ISLANDS',
 'VIRGIN ISLANDS (U.S.)',
 'VIETNAM',
 'VANUATU',
 'SAMOA',
 'KOSOVO',
 'YEMEN',
 'SOUTH AFRICA',
 'ZAMBIA',
 'ZIMBABWE']