0

I get an error ValueError: too many values to unpack when looping over a csv file.

import pandas as pd

class DataProcessing:

    def __init__(self, data):
        self.df = pd.read_csv(data, sep="\t").drop("Entrez_Gene_Id", axis=1, errors="ignore")
        self.df = self.df.loc[:, ~self.df.columns.duplicated()]
        self.df = self.df.set_index("Hugo_Symbol")
        self.df = self.df.sort_index()

    def split_data(self):
        X = self.df.iloc[:, :-1]
        y = self.df.iloc[:, -1]
        return X, y


def main():
    cna = DataProcessing(directory + "data_linear_cna.txt")

clin = pd.read_csv(directory + "data_clinical_patient_reduced.txt", sep="\t")

patients = {}
# get list of allowed patients
for index, row in clin:
    if row.OS_MONTHS != '[Not Available]':
        if float(row.OS_MONTHS) > 2 * 12:
            patients[row.PATIENT_ID] = 1


    #### Process the CNA data
    q = 5
    C = []
    G = []
    M = []

    # find common samples
    n = cna.df.shape[1]
    common_samples = {}

    cna_sample_index = {}

    for i in range(2, n):
    sample_name = list(cna.df)[i][0:-3]
    if sample_name in clin.df.iterrows():
        common_samples[sample_name] = 1
        cna_sample_index[sample_name] = i

main()

Traceback:

    Traceback (most recent call last):
  File "data_gen_files/main.py", line 309, in <module>
    main()
  File "data_gen_files/main.py", line 123, in main
    for index, row in clin:
ValueError: too many values to unpack (expected 2)
melolili
  • 383
  • 1
  • 7
  • You are trying to iterate over a dataframe. [This](https://stackoverflow.com/questions/16476924/how-to-iterate-over-rows-in-a-dataframe-in-pandas) might be of help – Pathi_rao Apr 22 '22 at 08:47

0 Answers0