<jupyter_start><jupyter_text><jupyter_code>import pandas as pd
import numpy as np
import re
!pip install -U -q PyDrive
 
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
 
# 1. Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

# Go to link, sign in, and paste in result
file_list = drive.ListFile({'q': "'1kE03N5LwmWDDsDescCPmlQxGsY7ZKEnT' in parents and trashed=false"}).GetList()
for file1 in file_list:
  print('title: %s, id: %s' % (file1['title'], file1['id']))
downloaded = drive.CreateFile({'id':"1BKZfd5WBLkryOSWI6t4g50bloTD8P6f3"})  
downloaded.GetContentFile('vehicles_cl.csv')       
df_orig = pd.read_csv('vehicles_cl.csv')
df_orig
df_cl = df_orig.copy()
df_cl['price'] = df_cl['price'].replace(0,np.NaN)
df_cl = df_cl.dropna(subset=['price'])
df_cl = df_cl[(df_cl['price'] >= np.percentile(df_cl['price'], 1)) &
          (df_cl['price'] <= np.percentile(df_cl['price'], 99))]
df_cl['price'].describe()
df_cl = df_cl.dropna(subset=['year', 'manufacturer', 'model', 'year'])
df_cl.isnull().sum()
df_cl.shape
df_cl.model.sample(50)
# EPA 
downloaded = drive.CreateFile({'id':"12aa_5F_dECaFGjQR5KYZwToAqhHouUNi"})  

downloaded.GetContentFile('vehicles.csv')  
df_epa = pd.read_csv('vehicles.csv')
df_epa.model.sample(50)
df_epa.make = df_epa.make.str.lower()

df_epa.model = df_epa.model.str.lower()<jupyter_output><empty_output><jupyter_text>Fuzzy Wuzzy attemps<jupyter_code>pip install fuzzywuzzy
from fuzzywuzzy import fuzz, process
# Start with epa, compare models where year and make is the same

# for row in df_epa:
#   if df_epa.year == df_cl.year:
#     print(fuzz.ratio(df_epa['model'][row], df_cl['model'][row]))


# Lets look at a simplified list

epa_models = sorted(df_epa['model'].unique())
cl_models = sorted(df_cl.model.unique())


for model in epa_models:
  for x  in range(len(cl_models)):
    print(fuzz.ratio(model, cl_models[x]))
df_epa['model'].nunique(), df['model'].nunique()
epa_models[2888]
grand_cherokee_ratios = []
for model in cl_models:
  grand_cherokee_ratios.append(fuzz.ratio(epa_models[2888], model))
max(grand_cherokee_ratios)
grand_cherokee_ratios.index(84)
cl_models[18845]
# Input Make model Year get a prediction?
sample_model = 'sivics'

cl_models = sorted(df_cl.model.unique())

def match_models(sample_model):
  model_ratios = []
  for model in cl_models:
    model_ratios.append(fuzz.ratio(sample_model, model))
  max_match = max(model_ratios)
  index_of_match = model_ratios.index(max_match)
  return cl_models[index_of_match]
match_models('Range Rover Evoque')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1393177737881508, 'fraction_numerical': 0.01651705565529623, 'mean_word_length': 6.449197860962567, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '385486', 'license': 'MIT', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1069, 'n_words': 202, 'path': 'notebooks/cl_epa_merge.ipynb', 'repo_name': 'JonNData/used-car-predictor', 'size': '2785'}