<jupyter_start><jupyter_text>Extracting Room InfoAlready added `room_info.split(' · ')`.<jupyter_code>import pandas as pd

df = pd.read_csv('alaska_entire_home_super_hosts_2021-01-09.csv')

df.room_info
df.room_info[0]
type(df.room_info[0])
room = df.room_info[0]

room
room.split("'")
len(room.split("'"))
room.split("'")[1]
split_info = room.split("'")

split_info
split_info = [i for i in room.split("'") if i not in '[], ']
split_info
split_info = [i.split() for i in room.split("'") if i not in '[], ']
split_info
split_info = [i.split() for i in room.split("'") if i not in '[], ']
split_info = {i[1]:i[0] for i in split_info}
split_info<jupyter_output><empty_output><jupyter_text>On different rooms... (verification)<jupyter_code>for room in df.room_info.sample(5): 
    split_info = [i.split() for i in room.split("'") if i not in '[], ']
    split_info = {i[1]:i[0] for i in split_info}
    print(split_info)
for room in df.room_info.sample(5): 
    split_info = [i.split() for i in room.split("'") if i not in '[], ']
#     split_info = {i[1]:i[0] for i in split_info}
    print(split_info)
for room in df.room_info.sample(15): 
    split_info = [i.split() for i in room.split("'") if i not in '[], ']
#     split_info = {i[1]:i[0] for i in split_info}
    print(split_info)<jupyter_output>[['2', 'guests'], ['1', 'bedroom'], ['0', 'beds'], ['Half-bath']]
[['4', 'guests'], ['1', 'bedroom'], ['1', 'bed'], ['1', 'bath']]
[['2', 'guests'], ['Studio'], ['1', 'bed'], ['1', 'bath']]
[['2', 'guests'], ['Studio'], ['1', 'bed'], ['0', 'baths']]
[['3', 'guests'], ['Studio'], ['2', 'beds'], ['0', 'baths']]
[['1', 'guest'], ['1', 'bedroom'], ['1', 'bed'], ['2', 'shared', 'baths']]
[['1', 'guest'], ['1', 'bedroom'], ['1', 'bed'], ['1', 'shared', 'bath']]
[['1', 'guest'], ['1', 'bedroom'], ['6', 'beds'], ['2', 'shared', 'baths']]
[['2', 'guests'], ['1', 'bedroom'], ['1', 'bed'], ['1', 'bath']]
[['2', 'guests'], ['1', 'bedroom'], ['1', 'bed'], ['1', 'bath']]
[['2', 'guests'], ['Studio'], ['1', 'bed'], ['Half-bath']]
[['3', 'guests'], ['1', 'bedroom'], ['2', 'beds'], ['0', 'baths']]
[['5', 'guests'], ['1', 'bedroom'], ['3', 'beds'], ['1', 'bath']]
[['2', 'guests'], ['1', 'bedroom'], ['1', 'bed'], ['1', 'bath']]
[['4', 'guests'], ['2', 'bedrooms'], ['2', 'beds'], ['1.5', 'baths']]<jupyter_text>add check for `['Studio']` (0 rooms).<jupyter_code>for room in df.room_info.sample(15): 
    split_info = [i.split() for i in room.split("'") if i not in '[], ']
    # add check for 'Studio' (0 rooms)
    split_info = {i[1]:i[0] if i != ['Studio'] else i for i in split_info}
    print(split_info)
new_list = []
for room in df.room_info.sample(10): 
    split_info = [i.split() for i in room.split("'") if i not in '[], ']
    for i in split_info:
        if i != ['Studio']:
            try:
                new_list.append(i)
            except:
                print(i)
                
                
new_list<jupyter_output><empty_output><jupyter_text>Add check for `['Half-bath']`.<jupyter_code>for room in df.room_info.sample(15): 
    split_info = [i.split() for i in room.split("'") if i not in '[], ']
    # add check for 'Studio' (0 rooms)
    split_info = {i[1]:i[0] if i not in [['Studio'], ['Half-bath']] else i for i in split_info}
    print(split_info)
new_list = []
for room in df.room_info.sample(100): 
    split_info = [i.split() for i in room.split("'") if i not in '[], ']
    for i in split_info:
        if i not in [['Studio'], ['Half-bath']]:
            try:
                new_list.append(i)
            except:
                if len(i)==1:
                    print(i)
                else:
                    raise Exception('idk')
                
                
new_list<jupyter_output><empty_output><jupyter_text>Add check for `['x', 'shared', 'bath']`...<jupyter_code>c = []

for room in df.room_info.sample(150):
    room_dict = {}
    split_info = [i.split() for i in room.split("'") if i not in '[], ']
    # add check for 'Studio' (0 rooms)
#     split_info = {i[1]:i[0] if i not in [['Studio'], ['Half-bath']] else i for i in split_info}
    for i in split_info:
        if i not in [['Studio'], ['Half-bath']]:
            if len(i) == 2:
                room_dict[i[1]] = i[0]
            # shared-baths
            elif len(i) == 3:
                i = [i[0], '-'.join([i[1], i[2]])]
                room_dict[i[1]] = i[0]
            else:
                raise Exception(f'unexpected room_info | unexpected split_info len(i)=={len(i)}!=2!=3')
        else:
            # Half-baths and Studios
            if i[0] == 'Studio':
                room_dict['is_studio'] = True
            room_dict[i[0]] = 0
    
    try:
        room_dict['bedrooms']
    except:
        try:
            room_dict['bedrooms'] = room_dict['bedroom']
        except:
            room_dict['bedrooms'] = room_dict['Studio']
         
    try:
        room_dict['baths']
    except:
        try:
            room_dict['baths'] = room_dict['bath']
        except:
            room_dict['baths'] = None
            
    room_dict['half_baths'] = room_dict.get('Half-bath')
    room_dict['shared_baths'] = room_dict.get('shared-baths')
    room_dict['is_studio'] = room_dict.get('is_studio', False)
            
    room_dict = {key:value for key,value in room_dict.items() if key in ['guests', 'bedrooms', 'beds', 'is_studio', 'baths', 'half_baths', 'shared_baths']}
            
    c.append(room_dict)
       
for d in c:
# #     if d['shared_baths'] != None:
# #         print(d)
#     if (d['half_baths'] != None) and (d['half_baths'] != 0):
#         print(d)
    if d['is_studio'] == True:
        print(d)
# c<jupyter_output>{'guests': '2', 'is_studio': True, 'bedrooms': 0, 'baths': '1', 'half_baths': None, 'shared_baths': None}
{'guests': '5', 'is_studio': True, 'beds': '3', 'bedrooms': 0, 'baths': None, 'half_baths': 0, 'shared_baths': None}
{'guests': '2', 'is_studio': True, 'bedrooms': 0, 'baths': None, 'half_baths': 0, 'shared_baths': None}
{'guests': '5', 'is_studio': True, 'beds': '4', 'bedrooms': 0, 'baths': '1', 'half_baths': None, 'shared_baths': None}
{'guests': '2', 'is_studio': True, 'baths': '0', 'bedrooms': 0, 'half_baths': None, 'shared_baths': None}
{'guests': '2', 'is_studio': True, 'baths': '0', 'bedrooms': 0, 'half_baths': None, 'shared_baths': None}
{'guests': '3', 'is_studio': True, 'baths': '0', 'bedrooms': 0, 'half_baths': None, 'shared_baths': None}
{'guests': '2', 'is_studio': True, 'bedrooms': 0, 'baths': None, 'half_baths': 0, 'shared_baths': None}
{'guests': '5', 'is_studio': True, 'beds': '3', 'bedrooms': 0, 'baths': None, 'half_baths': 0, 'shared_baths': None}
{'guests': '4',[...]<jupyter_text>Before<jupyter_code>def get_room_info(listing):
    """
    returns room info of listing 
    """
    room_info = listing.find('div', {'class', '_kqh46o'}).text
    room_info = room_info.split(' · ')
    return room_info<jupyter_output><empty_output><jupyter_text>After<jupyter_code>def get_room_info(listing):
    """
    returns room info of listing 
    """
    room_info = listing.find('div', {'class', '_kqh46o'}).text
    split_info = room_info.split(' · ')
    room_dict = {}
    for i in split_info:
        if i not in [['Studio'], ['Half-bath']]:
            if len(i) == 2:
                room_dict[i[1]] = i[0]
            # shared-baths
            elif len(i) == 3:
                i = [i[0], '-'.join([i[1], i[2]])]
                room_dict[i[1]] = i[0]
            else:
                raise Exception(f'unexpected room_info | unexpected split_info len(i)=={len(i)}!=2!=3')
        else:
            # Half-baths and Studios
            if i[0] == 'Studio':
                room_dict['is_studio'] = True
            room_dict[i[0]] = 0
    
    try:
        room_dict['bedrooms']
    except:
        try:
            room_dict['bedrooms'] = room_dict['bedroom']
        except:
            room_dict['bedrooms'] = room_dict['Studio']
         
    try:
        room_dict['baths']
    except:
        try:
            room_dict['baths'] = room_dict['bath']
        except:
            room_dict['baths'] = None
            
    room_dict['half_baths'] = room_dict.get('Half-bath')
    room_dict['shared_baths'] = room_dict.get('shared-baths')
    room_dict['is_studio'] = room_dict.get('is_studio', False)
            
    room_dict = {key:value for key,value in room_dict.items() if key in ['guests', 'bedrooms', 'beds', 'is_studio', 'baths', 'half_baths', 'shared_baths']}
            
    return room_dict<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21639344262295082, 'fraction_numerical': 0.019437939110070256, 'mean_word_length': 2.93232044198895, 'pattern_counts': {'":': 0, '<': 27, '<?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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '332944', 'license': 'Apache-2.0', 'n_tokens_mistral': 3376, 'n_tokens_neox': 3222, 'n_words': 754, 'path': 'wip_notebooks/03_cleaning/room_info.ipynb', 'repo_name': 'gumdropsteve/airbnb', 'size': '8540'}