# -*- coding: utf-8 -*-
"""
Created on Wed May 22 22:29:08 2019

@author: Shibo
"""

#def get_list_of_university_towns():
#    '''Returns a DataFrame of towns and the states they are in from the 
#    university_towns.txt list. The format of the DataFrame should be:
#    DataFrame( [ ["Michigan", "Ann Arbor"], ["Michigan", "Yipsilanti"] ], 
#    columns=["State", "RegionName"]  )
#    
#    The following cleaning needs to be done:
#
#    1. For "State", removing characters from "[" to the end.
#    2. For "RegionName", when applicable, removing every character from " (" to the end.
#    3. Depending on how you read the data, you may need to remove newline character '\n'. '''
#    
#    return "ANSWER"

import pandas as pd
import numpy as np
from scipy.stats import ttest_ind
pd.set_option('display.max_rows',1000)
statesname = {'OH': 'Ohio', 'KY': 'Kentucky', 'AS': 'American Samoa', 'NV': 'Nevada', 'WY': 'Wyoming', 'NA': 'National', 'AL': 'Alabama', 'MD': 'Maryland', 'AK': 'Alaska', 'UT': 'Utah', 'OR': 'Oregon', 'MT': 'Montana', 'IL': 'Illinois', 'TN': 'Tennessee', 'DC': 'District of Columbia', 'VT': 'Vermont', 'ID': 'Idaho', 'AR': 'Arkansas', 'ME': 'Maine', 'WA': 'Washington', 'HI': 'Hawaii', 'WI': 'Wisconsin', 'MI': 'Michigan', 'IN': 'Indiana', 'NJ': 'New Jersey', 'AZ': 'Arizona', 'GU': 'Guam', 'MS': 'Mississippi', 'PR': 'Puerto Rico', 'NC': 'North Carolina', 'TX': 'Texas', 'SD': 'South Dakota', 'MP': 'Northern Mariana Islands', 'IA': 'Iowa', 'MO': 'Missouri', 'CT': 'Connecticut', 'WV': 'West Virginia', 'SC': 'South Carolina', 'LA': 'Louisiana', 'KS': 'Kansas', 'NY': 'New York', 'NE': 'Nebraska', 'OK': 'Oklahoma', 'FL': 'Florida', 'CA': 'California', 'CO': 'Colorado', 'PA': 'Pennsylvania', 'DE': 'Delaware', 'NM': 'New Mexico', 'RI': 'Rhode Island', 'MN': 'Minnesota', 'VI': 'Virgin Islands', 'NH': 'New Hampshire', 'MA': 'Massachusetts', 'GA': 'Georgia', 'ND': 'North Dakota', 'VA': 'Virginia'}
newstatesname = {v : k for k, v in statesname.items()}
f = open("university_towns.txt", "r")
n=0
sta=()
df=pd.DataFrame(columns=["State", "RegionName"])
for x in f:
    if x.endswith("[edit]\n"):
        statename=x[:-7]
        newstatename=newstatesname[statename]
    else:
        if "(" in x:
            
            z=x.find("(")
            regionname=x[:z-1]
            
        else:
            regionname=x[:-1]
        df.loc[n,["State", "RegionName"]]=[statename,regionname]
        n=n+1


0b50bcdbdda3b01709556d0433c88de73cea22ca
<mask token>

<mask token>
pd.set_option('display.max_rows', 1000)
<mask token>
for x in f:
    if x.endswith('[edit]\n'):
        statename = x[:-7]
        newstatename = newstatesname[statename]
    else:
        if '(' in x:
            z = x.find('(')
            regionname = x[:z - 1]
        else:
            regionname = x[:-1]
        df.loc[n, ['State', 'RegionName']] = [statename, regionname]
        n = n + 1

<mask token>
pd.set_option('display.max_rows', 1000)
statesname = {'OH': 'Ohio', 'KY': 'Kentucky', 'AS': 'American Samoa', 'NV':
    'Nevada', 'WY': 'Wyoming', 'NA': 'National', 'AL': 'Alabama', 'MD':
    'Maryland', 'AK': 'Alaska', 'UT': 'Utah', 'OR': 'Oregon', 'MT':
    'Montana', 'IL': 'Illinois', 'TN': 'Tennessee', 'DC':
    'District of Columbia', 'VT': 'Vermont', 'ID': 'Idaho', 'AR':
    'Arkansas', 'ME': 'Maine', 'WA': 'Washington', 'HI': 'Hawaii', 'WI':
    'Wisconsin', 'MI': 'Michigan', 'IN': 'Indiana', 'NJ': 'New Jersey',
    'AZ': 'Arizona', 'GU': 'Guam', 'MS': 'Mississippi', 'PR': 'Puerto Rico',
    'NC': 'North Carolina', 'TX': 'Texas', 'SD': 'South Dakota', 'MP':
    'Northern Mariana Islands', 'IA': 'Iowa', 'MO': 'Missouri', 'CT':
    'Connecticut', 'WV': 'West Virginia', 'SC': 'South Carolina', 'LA':
    'Louisiana', 'KS': 'Kansas', 'NY': 'New York', 'NE': 'Nebraska', 'OK':
    'Oklahoma', 'FL': 'Florida', 'CA': 'California', 'CO': 'Colorado', 'PA':
    'Pennsylvania', 'DE': 'Delaware', 'NM': 'New Mexico', 'RI':
    'Rhode Island', 'MN': 'Minnesota', 'VI': 'Virgin Islands', 'NH':
    'New Hampshire', 'MA': 'Massachusetts', 'GA': 'Georgia', 'ND':
    'North Dakota', 'VA': 'Virginia'}
newstatesname = {v: k for k, v in statesname.items()}
f = open('university_towns.txt', 'r')
n = 0
sta = ()
df = pd.DataFrame(columns=['State', 'RegionName'])
for x in f:
    if x.endswith('[edit]\n'):
        statename = x[:-7]
        newstatename = newstatesname[statename]
    else:
        if '(' in x:
            z = x.find('(')
            regionname = x[:z - 1]
        else:
            regionname = x[:-1]
        df.loc[n, ['State', 'RegionName']] = [statename, regionname]
        n = n + 1

<mask token>
import pandas as pd
import numpy as np
from scipy.stats import ttest_ind
pd.set_option('display.max_rows', 1000)
statesname = {'OH': 'Ohio', 'KY': 'Kentucky', 'AS': 'American Samoa', 'NV':
    'Nevada', 'WY': 'Wyoming', 'NA': 'National', 'AL': 'Alabama', 'MD':
    'Maryland', 'AK': 'Alaska', 'UT': 'Utah', 'OR': 'Oregon', 'MT':
    'Montana', 'IL': 'Illinois', 'TN': 'Tennessee', 'DC':
    'District of Columbia', 'VT': 'Vermont', 'ID': 'Idaho', 'AR':
    'Arkansas', 'ME': 'Maine', 'WA': 'Washington', 'HI': 'Hawaii', 'WI':
    'Wisconsin', 'MI': 'Michigan', 'IN': 'Indiana', 'NJ': 'New Jersey',
    'AZ': 'Arizona', 'GU': 'Guam', 'MS': 'Mississippi', 'PR': 'Puerto Rico',
    'NC': 'North Carolina', 'TX': 'Texas', 'SD': 'South Dakota', 'MP':
    'Northern Mariana Islands', 'IA': 'Iowa', 'MO': 'Missouri', 'CT':
    'Connecticut', 'WV': 'West Virginia', 'SC': 'South Carolina', 'LA':
    'Louisiana', 'KS': 'Kansas', 'NY': 'New York', 'NE': 'Nebraska', 'OK':
    'Oklahoma', 'FL': 'Florida', 'CA': 'California', 'CO': 'Colorado', 'PA':
    'Pennsylvania', 'DE': 'Delaware', 'NM': 'New Mexico', 'RI':
    'Rhode Island', 'MN': 'Minnesota', 'VI': 'Virgin Islands', 'NH':
    'New Hampshire', 'MA': 'Massachusetts', 'GA': 'Georgia', 'ND':
    'North Dakota', 'VA': 'Virginia'}
newstatesname = {v: k for k, v in statesname.items()}
f = open('university_towns.txt', 'r')
n = 0
sta = ()
df = pd.DataFrame(columns=['State', 'RegionName'])
for x in f:
    if x.endswith('[edit]\n'):
        statename = x[:-7]
        newstatename = newstatesname[statename]
    else:
        if '(' in x:
            z = x.find('(')
            regionname = x[:z - 1]
        else:
            regionname = x[:-1]
        df.loc[n, ['State', 'RegionName']] = [statename, regionname]
        n = n + 1

# -*- coding: utf-8 -*-
"""
Created on Wed May 22 22:29:08 2019

@author: Shibo
"""

#def get_list_of_university_towns():
#    '''Returns a DataFrame of towns and the states they are in from the 
#    university_towns.txt list. The format of the DataFrame should be:
#    DataFrame( [ ["Michigan", "Ann Arbor"], ["Michigan", "Yipsilanti"] ], 
#    columns=["State", "RegionName"]  )
#    
#    The following cleaning needs to be done:
#
#    1. For "State", removing characters from "[" to the end.
#    2. For "RegionName", when applicable, removing every character from " (" to the end.
#    3. Depending on how you read the data, you may need to remove newline character '\n'. '''
#    
#    return "ANSWER"

import pandas as pd
import numpy as np
from scipy.stats import ttest_ind
pd.set_option('display.max_rows',1000)
statesname = {'OH': 'Ohio', 'KY': 'Kentucky', 'AS': 'American Samoa', 'NV': 'Nevada', 'WY': 'Wyoming', 'NA': 'National', 'AL': 'Alabama', 'MD': 'Maryland', 'AK': 'Alaska', 'UT': 'Utah', 'OR': 'Oregon', 'MT': 'Montana', 'IL': 'Illinois', 'TN': 'Tennessee', 'DC': 'District of Columbia', 'VT': 'Vermont', 'ID': 'Idaho', 'AR': 'Arkansas', 'ME': 'Maine', 'WA': 'Washington', 'HI': 'Hawaii', 'WI': 'Wisconsin', 'MI': 'Michigan', 'IN': 'Indiana', 'NJ': 'New Jersey', 'AZ': 'Arizona', 'GU': 'Guam', 'MS': 'Mississippi', 'PR': 'Puerto Rico', 'NC': 'North Carolina', 'TX': 'Texas', 'SD': 'South Dakota', 'MP': 'Northern Mariana Islands', 'IA': 'Iowa', 'MO': 'Missouri', 'CT': 'Connecticut', 'WV': 'West Virginia', 'SC': 'South Carolina', 'LA': 'Louisiana', 'KS': 'Kansas', 'NY': 'New York', 'NE': 'Nebraska', 'OK': 'Oklahoma', 'FL': 'Florida', 'CA': 'California', 'CO': 'Colorado', 'PA': 'Pennsylvania', 'DE': 'Delaware', 'NM': 'New Mexico', 'RI': 'Rhode Island', 'MN': 'Minnesota', 'VI': 'Virgin Islands', 'NH': 'New Hampshire', 'MA': 'Massachusetts', 'GA': 'Georgia', 'ND': 'North Dakota', 'VA': 'Virginia'}
newstatesname = {v : k for k, v in statesname.items()}
f = open("university_towns.txt", "r")
n=0
sta=()
df=pd.DataFrame(columns=["State", "RegionName"])
for x in f:
    if x.endswith("[edit]\n"):
        statename=x[:-7]
        newstatename=newstatesname[statename]
    else:
        if "(" in x:
            
            z=x.find("(")
            regionname=x[:z-1]
            
        else:
            regionname=x[:-1]
        df.loc[n,["State", "RegionName"]]=[statename,regionname]
        n=n+1

