From b7605f5fa62fc162256cef550c8dadd32b69cd6f Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Sat, 5 Aug 2023 14:33:59 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- Analysis1/Analysis1.py | 8 +++--- Analysis2/Analysis2.py | 6 ++-- Analysis3/Analysis3.py | 6 ++-- Analysis4/Analysis4.py | 4 +-- Analysis5/Analysis5.py | 8 ++++-- DataPreparation/DataPreparation.py | 44 ++++++++++++++++++++---------- 6 files changed, 46 insertions(+), 30 deletions(-) diff --git a/Analysis1/Analysis1.py b/Analysis1/Analysis1.py index a1cde35..a17b654 100644 --- a/Analysis1/Analysis1.py +++ b/Analysis1/Analysis1.py @@ -29,7 +29,7 @@ # absolute path till parent folder abs_path = os.getcwd() path_array = abs_path.split("/") -path_array = path_array[:len(path_array)-1] +path_array = path_array[:-1] homefolder_path = "" for i in path_array[1:]: homefolder_path = homefolder_path + "/" + i @@ -60,7 +60,7 @@ # In[33]: # saving the plot -fig.savefig(abs_path + "/Plots/vehicle-distribution.png") +fig.savefig(f"{abs_path}/Plots/vehicle-distribution.png") # ## Variation of the price range by the vehicle type @@ -78,7 +78,7 @@ # In[45]: # saving the plot -fig.savefig(abs_path + "/Plots/price-vehicleType-boxplot.png") +fig.savefig(f"{abs_path}/Plots/price-vehicleType-boxplot.png") # ## Total count of vehicles by type available on ebay for sale @@ -97,7 +97,7 @@ # In[54]: # saving the plot -g.savefig(abs_path + "/Plots/count-vehicleType.png") +g.savefig(f"{abs_path}/Plots/count-vehicleType.png") # In[ ]: diff --git a/Analysis2/Analysis2.py b/Analysis2/Analysis2.py index 574aac7..844ffb3 100644 --- a/Analysis2/Analysis2.py +++ b/Analysis2/Analysis2.py @@ -27,7 +27,7 @@ # absolute path till parent folder abs_path = os.getcwd() path_array = abs_path.split("/") -path_array = path_array[:len(path_array)-1] +path_array = path_array[:-1] homefolder_path = "" for i in path_array[1:]: homefolder_path = homefolder_path + "/" + i @@ -58,7 +58,7 @@ # In[51]: # saving the plot -g.savefig((abs_path + "/Plots/brand-vehicleCount.png")) +g.savefig(f"{abs_path}/Plots/brand-vehicleCount.png") # ## Average price for vehicles based on the type of vehicle as well as on the type of gearbox @@ -75,7 +75,7 @@ # In[64]: # saving the plot -fig.savefig((abs_path + "/Plots/vehicletype-gearbox-price.png")) +fig.savefig(f"{abs_path}/Plots/vehicletype-gearbox-price.png") # In[ ]: diff --git a/Analysis3/Analysis3.py b/Analysis3/Analysis3.py index 83a1f11..a6ee05c 100644 --- a/Analysis3/Analysis3.py +++ b/Analysis3/Analysis3.py @@ -25,7 +25,7 @@ # absolute path till parent folder abs_path = os.getcwd() path_array = abs_path.split("/") -path_array = path_array[:len(path_array)-1] +path_array = path_array[:-1] homefolder_path = "" for i in path_array[1:]: homefolder_path = homefolder_path + "/" + i @@ -55,7 +55,7 @@ # In[8]: # saving the plot -fig.savefig((abs_path + "/Plots/vehicletype-fueltype-price.png")) +fig.savefig(f"{abs_path}/Plots/vehicletype-fueltype-price.png") # ## Average power of a vehicle by vehicle type and gearbox type @@ -74,7 +74,7 @@ # In[19]: # saving the plot -fig.savefig((abs_path + "/Plots/vehicletype-fueltype-power.png")) +fig.savefig(f"{abs_path}/Plots/vehicletype-fueltype-power.png") # In[ ]: diff --git a/Analysis4/Analysis4.py b/Analysis4/Analysis4.py index 052c0ce..5e3a291 100644 --- a/Analysis4/Analysis4.py +++ b/Analysis4/Analysis4.py @@ -25,7 +25,7 @@ # absolute path till parent folder abs_path = os.getcwd() path_array = abs_path.split("/") -path_array = path_array[:len(path_array)-1] +path_array = path_array[:-1] homefolder_path = "" for i in path_array[1:]: homefolder_path = homefolder_path + "/" + i @@ -69,7 +69,7 @@ # In[12]: -fig.savefig((abs_path + "/Plots/heatmap-price-brand-vehicleType.png")) +fig.savefig(f"{abs_path}/Plots/heatmap-price-brand-vehicleType.png") # In[13]: diff --git a/Analysis5/Analysis5.py b/Analysis5/Analysis5.py index a63d254..3eecc02 100644 --- a/Analysis5/Analysis5.py +++ b/Analysis5/Analysis5.py @@ -29,7 +29,7 @@ # absolute path till parent folder abs_path = os.getcwd() path_array = abs_path.split("/") -path_array = path_array[:len(path_array)-1] +path_array = path_array[:-1] homefolder_path = "" for i in path_array[1:]: homefolder_path = homefolder_path + "/" + i @@ -71,13 +71,15 @@ fig, ax = plt.subplots(figsize=(8,5)) sns.set_palette(sns.xkcd_palette(colors)) sns.stripplot(x="vehicleType", y="NoOfDaysOnline", hue="gearbox", split=True, data=frame,size=8, alpha=0.5, jitter=True) -ax.set_title("No of days a add is online before the vehicles of brand " + search_term + " is sold") +ax.set_title( + f"No of days a add is online before the vehicles of brand {search_term} is sold" +) plt.show() # In[27]: -fig.savefig((abs_path + "/Plots/vehicletype-NoOfDaysOnline.png")) +fig.savefig(f"{abs_path}/Plots/vehicletype-NoOfDaysOnline.png") # In[ ]: diff --git a/DataPreparation/DataPreparation.py b/DataPreparation/DataPreparation.py index e36dd5f..2b816d9 100644 --- a/DataPreparation/DataPreparation.py +++ b/DataPreparation/DataPreparation.py @@ -305,13 +305,12 @@ # creating folder structure as per brand of vehicle fileName = abs_path + "/ShellScripts/CreateFolder.sh" -file = open(fileName, "w+") -baseString = "mkdir -p " + abs_path + "/CleanData/DataForAnalysis/" -for b in list(t["brand"].unique()): - newString = baseString + b + "\n" - file.write(newString) -file.write("mkdir -p " + abs_path + "/CleanData/CleanedDataSet") -file.close() +with open(fileName, "w+") as file: + baseString = "mkdir -p " + abs_path + "/CleanData/DataForAnalysis/" + for b in list(t["brand"].unique()): + newString = baseString + b + "\n" + file.write(newString) + file.write("mkdir -p " + abs_path + "/CleanData/CleanedDataSet") st = os.stat(fileName) os.chmod(fileName, st.st_mode | stat.S_IEXEC) subprocess.call(fileName,shell=True) @@ -328,14 +327,29 @@ # splitting the the records based on brand and vehicleType fileName = abs_path + "/ShellScripts/CreateFiles.sh" -file = open(fileName, "w+") -baseString_before = '''awk 'BEGIN{FS=OFS=","} FNR == 1 {print} ''' -baseString_after = " {print}' " + abs_path + "/CleanData/CleanedDataSet/cleaned_autos.csv" + " >> " + abs_path + "/CleanData/DataForAnalysis/" -for b in list(df["brand"].unique()): - for typ in list(df[df["brand"] == b]["vehicleType"].unique()): - newString = baseString_before + '$15 == ' + '"' + b + '"' + ' && $7 == ' + '"' + typ + '"' + baseString_after + b + "/" + b + "_" + typ + ".csv" + "\n" - file.write(newString) -file.close() +with open(fileName, "w+") as file: + baseString_before = '''awk 'BEGIN{FS=OFS=","} FNR == 1 {print} ''' + baseString_after = " {print}' " + abs_path + "/CleanData/CleanedDataSet/cleaned_autos.csv" + " >> " + abs_path + "/CleanData/DataForAnalysis/" + for b in list(df["brand"].unique()): + for typ in list(df[df["brand"] == b]["vehicleType"].unique()): + newString = ( + f'{baseString_before}$15 == "' + + b + + '"' + + ' && $7 == ' + + '"' + + typ + + '"' + + baseString_after + + b + + "/" + + b + + "_" + + typ + + ".csv" + + "\n" + ) + file.write(newString) st = os.stat(fileName) os.chmod(fileName, st.st_mode | stat.S_IEXEC) subprocess.call(fileName,shell=True)