I have a dataframe like this:
This dataframe has several columns. Two are of type float
: price
and change
, while
You can convert column-by-column:
by_column = [df[x].values.tolist() for x in df.columns]
This will preserve the data type of each column.
Than convert to the structure you want:
list(list(x) for x in zip(*by_column))
You can do it in one line:
list(list(x) for x in zip(*(df[x].values.tolist() for x in df.columns)))
You can check what datatypes your columns have with:
df.info()
Very likely your column amount
is of type float
. Do you have any NaN
in this column? These are always of type float
and would make the whole column float
.
You can cast to int
with:
df.values.astype(int).tolist()