<jupyter_start><jupyter_text>Insert Photos for Top 25<jupyter_code># This notebook is useful but, defunct as it is missing 'photos.csv'
import pandas as pd

df = pd.read_csv('./extraneous_datasets/completeddataset.csv')
print(df.shape)
df.head()
Indiana = df[df['state'] == 'Indiana']
Indiana.shape
df.columns
df.isnull().sum()
df.dtypes
photos = pd.read_csv('./photos.csv', header = None)
photos.head()
photos.columns = ['city', 'photo_url']
photos.head()
df.shape
final = pd.merge(df, photos, on='city', how='outer')
photos_final = pd.merge(photos, df, on='city', how='left')
final.isnull().sum()
import numpy as np

final = final.replace(np.NaN, "None")
final.isnull().sum()
final.head()
#df.to_csv('final_add_photos.csv')
photos_final.isnull().sum()
photos_final.shape
photos_final.to_csv('photos_big.csv')<jupyter_output><empty_output><jupyter_text>Filtering DF<jupyter_code>df.head()
df.columns
df2 = pd.read_csv('./completeddataset.csv')
df2.head()
df2.columns
pd.set_option('display.float_format', lambda x: '%.5f' % x)
df['population'].describe()

# Tiny: 5-10k
# Small: 10-30k
# Medium: 30k-100k
# Large: 100k-1 million
# Extra Large: 1 million+
def pop_rank(row):
    if row['population'] < 10000:
        val = 1
    elif row['population'] < 30000:
        val = 2
    elif row['population'] < 100000:
        val = 3
    elif row['population'] < 1000000:
        val = 4
    else:
        val = 5
    return val

df2['pop_rank'] = df.apply(pop_rank, axis=1)
df['population_change'].describe()

# Decreasing Rapidly < -25
# Decreasing < -5
# Stable < 5
# Increasing >= 5
# Increasing Rapidly >= 25
def pop_ch_rank(row):
    if row['population_change'] < -25:
        val = 1
    elif row['population_change'] < -5:
        val = 2
    elif row['population_change'] < 5:
        val = 3
    elif row['population_change'] >= 5:
        val = 4
    else:
        val = 5
    return val

df2['pop_ch_rank'] = df.apply(pop_ch_rank, axis=1)
df['Median_Age'].describe()

# Very Young < 20
# Young < 35
# Middle-Aged < 50
# Old < 65
# Retired
def med_age_rank(row):
    if row['Median_Age'] < 20:
        val = 1
    elif row['Median_Age'] < 35:
        val = 2
    elif row['Median_Age'] < 50:
        val = 3
    elif row['Median_Age'] >= 65:
        val = 4
    else:
        val = 5
    return val

df2['med_age_rank'] = df.apply(med_age_rank, axis=1)
df['HDTIscorenorm'].describe()

# Very Low < 20
# Low < 40
# Medium < 60
# High < 80
# Very High
def house_cost(row):
    if row['HDTIscorenorm'] < 20:
        val = 1
    elif row['HDTIscorenorm'] < 40:
        val = 2
    elif row['HDTIscorenorm'] < 60:
        val = 3
    elif row['HDTIscorenorm'] < 80:
        val = 4
    else:
        val = 5
    return val

df2['house_cost'] = df.apply(house_cost, axis=1)
df['RTIscorenorm'].describe()

# Very Low < 20
# Low < 40
# Medium < 60
# High < 80
# Very High
def rent_cost(row):
    if row['RTIscorenorm'] < 20:
        val = 1
    elif row['RTIscorenorm'] < 40:
        val = 2
    elif row['RTIscorenorm'] < 60:
        val = 3
    elif row['RTIscorenorm'] < 80:
        val = 4
    else:
        val = 5
    return val

df2['rent_cost'] = df.apply(rent_cost, axis=1)
df['Population_Density'].describe()

# Very Low < 500
# Low < 1000
# Medium < 2000
# High < 5000
# Very High
def pop_density(row):
    if row['Population_Density'] < 500:
        val = 1
    elif row['Population_Density'] < 1000:
        val = 2
    elif row['Population_Density'] < 2000:
        val = 3
    elif row['Population_Density'] < 5000:
        val = 4
    else:
        val = 5
    return val

df2['pop_density'] = df.apply(pop_density, axis=1)
df['Cost_of_Living_Index'].describe()

# Very Low < 75
# Low < 100
# Medium < 125
# High < 150
# Very High
def cli_index(row):
    if row['Cost_of_Living_Index'] < 75:
        val = 1
    elif row['Cost_of_Living_Index'] < 100:
        val = 2
    elif row['Cost_of_Living_Index'] < 125:
        val = 3
    elif row['Cost_of_Living_Index'] < 150:
        val = 4
    else:
        val = 5
    return val

df2['cli_index'] = df.apply(cli_index, axis=1)
df['Average_Commute_Time'].describe()

# Very Low < 10
# Low < 15
# Medium < 20
# High < 30
# Very High
def avg_commute(row):
    if row['Average_Commute_Time'] < 10:
        val = 1
    elif row['Average_Commute_Time'] < 15:
        val = 2
    elif row['Average_Commute_Time'] < 20:
        val = 3
    elif row['Average_Commute_Time'] < 30:
        val = 4
    else:
        val = 5
    return val

df2['avg_commute'] = df.apply(avg_commute, axis=1)
df['AQI'].describe()

# Very Good < 101
# Good < 250
# Medium < 500
# Bad < 750
# Very Bad
def air(row):
    if row['AQI'] < 10:
        val = 1
    elif row['AQI'] < 15:
        val = 2
    elif row['AQI'] < 20:
        val = 3
    elif row['AQI'] < 30:
        val = 4
    else:
        val = 5
    return val

df2['air'] = df.apply(air, axis=1)
df2.head()
df2.to_csv('final_with_rank_2.csv')
florida = df2[df2['state'] == 'Florida']
florida<jupyter_output><empty_output><jupyter_text>Recommendation Engine<jupyter_code>state = ['California', 'Washington', 'Texas']
multiple = []

for item in state:
    frame = df[df['state'] == item]
    multiple.append(frame)
    
states = pd.concat(multiple[0:], ignore_index = True)
    
# if len(state) == 1:
#     states = multiple[0]
# elif len(state) == 2:
#     states = pd.concat([multiple[0], multiple[1]], ignore_index = True)
# elif len(state) == 3:
#     states = pd.concat([multiple[0], multiple[1], multiple[2]], ignore_index = True)

#states = df[df['state'] == state]
print(states.shape)
states.tail()
sort = states.sort_values(by = 'LivabilityScore', ascending = False)
sort
list = [1, 2, 3, 0]

for x in list:
    if x != 0:
        print(x)
# parameter = [['pop_rank', 3],
#             ['pop_ch_rank', 0],
#             ['med_age_rank', 0],
#             ['house_cost', 0],
#             ['rent_cost', 0],
#             ['pop_density', 0],
#             ['cli_index', 0],
#             ['avg_commute', 0],
#             ['air', 0]]

# states.query(' and '.join(['{0}=={1}'.format(x[0], x[1]) for x in parameter))
dict = sort.to_dict('records')
top_5 = dict[0]['city']
top_2 = dict[1]['city']
top_5, top_2<jupyter_output><empty_output><jupyter_text>Create "final_0318"<jupyter_code>state = 'California'
pop = '3'
pop_ch = '0'
med_age = '0'
hdti = '0'
rti = '0'
pop_dense = '0'
col = '0'
drive = '0'
aqi = '0'
if state != 'None':
    states = df[df['state'] == state]
else:
    states = df
my_dict = {0: 'dog', 1: 'apple', 2: 'ball', 3: 'bike', 4: 'kite', 5: 'child'}
len(my_dict)
def top_five(dictionary):
    length = len(dictionary)
    
    list = []
    
    for item in range(length):
        list.append(dictionary[item])
        
    return list[0:5]
    
top_five(my_dict)
import pandas as pd 
data = pd.read_csv('./final_with_rank_2.csv')
data.columns
data['id'] = data['Unnamed: 0']
data.columns
data = data.drop(['Unnamed: 0'], axis = 1)
data.columns
data.to_csv('final_0318.csv')<jupyter_output><empty_output><jupyter_text>Combination Testing<jupyter_code>import pandas as pd
df = pd.read_csv('final_0318.csv')
df.head()
df.columns
## CLI = 1
## Age = 1
## Pop = 5
## Comm = 1

df['avg_commute'].value_counts()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16278428669882838, 'fraction_numerical': 0.045899379738111645, 'mean_word_length': 3.017718715393134, 'pattern_counts': {'":': 0, '<': 86, '<?xml version=': 0, '>': 25, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '68647', 'license': 'MIT', 'n_tokens_mistral': 3049, 'n_tokens_neox': 2686, 'n_words': 651, 'path': 'defunct_notebooks/defunct_Photos, Filtering, and Recommendation - Anika.ipynb', 'repo_name': 'BrianThomasRoss/juxta-city-data-ds', 'size': '7255'}