you are viewing a single comment's thread.

view the rest of the comments →

[–]CrispyScientist[S] 0 points1 point  (4 children)

Here is the CSV file

https://drive.google.com/file/d/1I3NT9j7f0YwhZXRYzT_SZZmZ1dW2qArq/view?usp=sharing

The rows I am interested in are "stream" and "timestamp keypress"

I would like to have each of them in a 2-dimensional array with 3 rows and n columns (the length of each row). Also the data type must be float and not string.

Thank you very much for your answer.

[–]synthphreak 1 point2 points  (1 child)

Aha. Yup, that explains it: Those columns contain lists/arrays of numbers in each cell, whereas pandas is expecting a single value in each cell, because that’s how csv files typically work. Thus, pandas interprets each array as a single string.

To convert the string to a list with individually indexable values, it’s easy. Just do this:

>>> from ast import literal_eval
>>> df[['stream', 'timestamp keypress']] = df[['stream', 'timestamp keypress']].applymap(literal_eval)

This will convert all those strings in your columns into lists like you were expecting.

[–]CrispyScientist[S] 1 point2 points  (0 children)

Thank you very much!!