Question: How can I fix this code so that the data given from the Plant _ data excel sheet imports and gives the highest and lowest

How can I fix this code so that the data given from the Plant_data excel sheet imports and gives the highest and lowest correlation. Then, displays the code in a pdf folder and the console? (Code is not appearing on console or pdf file)
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
def read_to_values(file_path):
with open(file_path) as csvfile:
reader = csv.DictReader(csvfile)
atm_temp =[]
soil_temp =[]
atm_hum =[]
soil_hum =[]
for row in reader:
atm_temp.append(float(row['Atmosphere Temp']))
soil_temp.append(float(row['Soil Temperature']))
atm_hum.append(float(row['Atmosphere Humidity']))
soil_hum.append(float(row['Soil Humidity']))
return atm_temp, soil_temp, atm_hum, soil_hum
def corr_calc(atm_temp, soil_temp, atm_hum, soil_hum):
# Correlation Calculations
correlations = atm_temp, soil_temp, atm_hum, soil_hum.corr(method='spearman')
# Highest and Lowest Correlations
correlations = correlations.unstack().sort_values(ascending=False)
highest_positive_corr = correlations[(correlations <1) & (correlations >=0)].index[0]
highest_negative_corr = correlations[correlations <0].index[0]
result1= correlations[highest_positive_corr]
result2= correlations[highest_negative_corr]
print(f"Highest Positive Correlation: {highest_positive_corr}- Correlation Value: {result1:.2f}")
print(f"Highest Negative Correlation: {highest_negative_corr}- Correlation Value: {result2:.2f}")
return highest_positive_corr, highest_negative_corr
def plot_me(df, col1, col2, title):
# Plot scatter plots with regression lines
sns.lmplot(x=col1, y=col2, data=df)
plt.title(title)
plt.xlabel(col1)
plt.ylabel(col2)
plt.tight_layout()
plt.savefig('/content/drive/MyDrive/Colab Notebooks/Plant_Corr.pdf')
plt.show()
def main():
file_path ="/content/drive/MyDrive/Colab Notebooks/Plant_Data_OG.csv"
atm_temp, soil_temp, atm_hum, soil_hum = read_to_values()
highest_positive_corr, highest_negative_corr = corr_calc(atm_temp, soil_temp, atm_hum, soil_hum)
plot_me(atm_temp, soil_temp, atm_hum, soil_hum, highest_positive_corr[0], highest_positive_corr[1], "Highest Positive Correlation")
plot_me(atm_temp, soil_temp, atm_hum, soil_hum, highest_negative_corr[0], highest_negative_corr[1], "Highest Negative Correlation")
if __name__=="__main__":
main

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!