39

I'm trying to append certain columns of Pandas Data Frames from CSV files into a numpy array. I have no idea how to instantiate an empty numpy array, so I'm testing it first with a list.

def windows(files):
    x = []
    for my_files in files:
        with open(os.path.join("/Users", "saqibali", "PycharmProjects", "sensorLogProject", "Data", my_files),
              'rU') as my_file:
            df = pd.DataFrame(columns=['timestamp', 'time skipped', 'x', 'y', 'z', 'label']).set_index('timestamp')
            for d in sliding_window(sample_difference(my_file), 500, 250):
                df = df.append(d[['x', 'y', 'z']])
            x.append(df.values.toList())
    return x

I get the error in the title, and it doesn't make sense to me because x is a list and df is a Data Frame.

0

1 Answer 1

56

The method name is all lowercase: tolist.

So you need to change the offending line to:

x.append(df.values.tolist())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.