Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications Dexa 2022 Workshops 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 In Computer And Information Science 33

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Alfred Taudes ,Atif Mashkoor ,Johannes Sametinger ,Jorge Martinez-Gil ,Florian Sobieczky ,Lukas Fischer ,Rudolf Ramler ,Maqbool Khan ,Gerald Czech

1st Edition

3031143426, 978-3031143427

More Books

Students also viewed these Databases questions

Question

What is the purpose of ISO 31000:2009?

Answered: 1 week ago

Question

c. What were you expected to do when you grew up?

Answered: 1 week ago