help with code for lab /u/No_Air834 Python Education

ok i’m going to say i’m sorry in advance – the code i’m working with is chatgpt generated, i know it’s horrible for coding, but i have literally 0 experience with python and i need it for this specific thing for my lab.

i need it to run to load an excel file, calculate the averages for values in a column titled “plddt” for each protein. so, for example, with the data in the image below, it would find that the average “plddt” value for protein 1 would be the average of the values in column I for rows 2 through 9.

the problem i’m having is that i don’t know if the code chatgpt generated even works, and i don’t know how to put it in a new file and execute it to test in the first place. please explain this to me like i’m 4, i’ve been looking all over the internet for guides for hours and somehow still haven’t figured it out. i would greatly appreciate it, thank you all so much:) and please let me know if i’ve explained something poorly or done something wrong u_u

import pandas as pd

import os

# Load the Excel file

file_path = '/mnt/data/HTT_data.xlsx'

try:

data = pd.read_excel(file_path)

except FileNotFoundError:

raise FileNotFoundError(f"The file at {file_path} does not exist. Please check the path and try again.")

except Exception as e:

raise Exception(f"An error occurred while reading the Excel file: {e}")

# Check if required columns exist

if 'residue' not in data.columns or 'plddt' not in data.columns:

raise ValueError("The Excel file must contain 'residue' and 'plddt' columns.")

# Group by 'residue' and calculate the average of 'plddt'

average_plddt = data.groupby('residue')['plddt'].mean().reset_index()

# Rename columns for clarity

average_plddt.columns = ['residue', 'average_plddt']

# Save the results to a new Excel file

output_file = '/mnt/data/average_plddt_results.xlsx'

if not os.access(os.path.dirname(output_file), os.W_OK):

raise PermissionError(f"The directory {os.path.dirname(output_file)} is not writable. Please check permissions.")

average_plddt.to_excel(output_file, index=False)

print(f"The averages have been calculated and saved to: {output_file}")

https://preview.redd.it/79wk9qebma7e1.png?width=918&format=png&auto=webp&s=27985ed9eeff1c680d54661b228fe6fab30a80d6

submitted by /u/No_Air834
[link] [comments]

​r/learnpython ok i’m going to say i’m sorry in advance – the code i’m working with is chatgpt generated, i know it’s horrible for coding, but i have literally 0 experience with python and i need it for this specific thing for my lab. i need it to run to load an excel file, calculate the averages for values in a column titled “plddt” for each protein. so, for example, with the data in the image below, it would find that the average “plddt” value for protein 1 would be the average of the values in column I for rows 2 through 9. the problem i’m having is that i don’t know if the code chatgpt generated even works, and i don’t know how to put it in a new file and execute it to test in the first place. please explain this to me like i’m 4, i’ve been looking all over the internet for guides for hours and somehow still haven’t figured it out. i would greatly appreciate it, thank you all so much:) and please let me know if i’ve explained something poorly or done something wrong u_u import pandas as pd import os # Load the Excel file file_path = ‘/mnt/data/HTT_data.xlsx’ try: data = pd.read_excel(file_path) except FileNotFoundError: raise FileNotFoundError(f”The file at {file_path} does not exist. Please check the path and try again.”) except Exception as e: raise Exception(f”An error occurred while reading the Excel file: {e}”) # Check if required columns exist if ‘residue’ not in data.columns or ‘plddt’ not in data.columns: raise ValueError(“The Excel file must contain ‘residue’ and ‘plddt’ columns.”) # Group by ‘residue’ and calculate the average of ‘plddt’ average_plddt = data.groupby(‘residue’)[‘plddt’].mean().reset_index() # Rename columns for clarity average_plddt.columns = [‘residue’, ‘average_plddt’] # Save the results to a new Excel file output_file = ‘/mnt/data/average_plddt_results.xlsx’ if not os.access(os.path.dirname(output_file), os.W_OK): raise PermissionError(f”The directory {os.path.dirname(output_file)} is not writable. Please check permissions.”) average_plddt.to_excel(output_file, index=False) print(f”The averages have been calculated and saved to: {output_file}”) https://preview.redd.it/79wk9qebma7e1.png?width=918&format=png&auto=webp&s=27985ed9eeff1c680d54661b228fe6fab30a80d6 submitted by /u/No_Air834 [link] [comments] 

ok i’m going to say i’m sorry in advance – the code i’m working with is chatgpt generated, i know it’s horrible for coding, but i have literally 0 experience with python and i need it for this specific thing for my lab.

i need it to run to load an excel file, calculate the averages for values in a column titled “plddt” for each protein. so, for example, with the data in the image below, it would find that the average “plddt” value for protein 1 would be the average of the values in column I for rows 2 through 9.

the problem i’m having is that i don’t know if the code chatgpt generated even works, and i don’t know how to put it in a new file and execute it to test in the first place. please explain this to me like i’m 4, i’ve been looking all over the internet for guides for hours and somehow still haven’t figured it out. i would greatly appreciate it, thank you all so much:) and please let me know if i’ve explained something poorly or done something wrong u_u

import pandas as pd

import os

# Load the Excel file

file_path = '/mnt/data/HTT_data.xlsx'

try:

data = pd.read_excel(file_path)

except FileNotFoundError:

raise FileNotFoundError(f"The file at {file_path} does not exist. Please check the path and try again.")

except Exception as e:

raise Exception(f"An error occurred while reading the Excel file: {e}")

# Check if required columns exist

if 'residue' not in data.columns or 'plddt' not in data.columns:

raise ValueError("The Excel file must contain 'residue' and 'plddt' columns.")

# Group by 'residue' and calculate the average of 'plddt'

average_plddt = data.groupby('residue')['plddt'].mean().reset_index()

# Rename columns for clarity

average_plddt.columns = ['residue', 'average_plddt']

# Save the results to a new Excel file

output_file = '/mnt/data/average_plddt_results.xlsx'

if not os.access(os.path.dirname(output_file), os.W_OK):

raise PermissionError(f"The directory {os.path.dirname(output_file)} is not writable. Please check permissions.")

average_plddt.to_excel(output_file, index=False)

print(f"The averages have been calculated and saved to: {output_file}")

https://preview.redd.it/79wk9qebma7e1.png?width=918&format=png&auto=webp&s=27985ed9eeff1c680d54661b228fe6fab30a80d6

submitted by /u/No_Air834
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *