Define a column type as 'list' in Pandas Define a column type as 'list' in Pandas pandas pandas

Define a column type as 'list' in Pandas


It seems to me that you are building a wrong data model.The model is not in 1st normal form (1NF) and you will have many troubles using it.Please, try to use a normalized model.

   Brand     price0  Nike     50.01  Nike     60.02  Nike     70.03  Puma     30.04  Puma     100.0

You can get any computed value from this model with ease.


You can use your brands as column names:

import pandas as pddf = pd.DataFrame({'Nike' : [[1,5,198,0,0,35],[0.5,0.3,0.2]]},index = ['count','floats'])

and then you can add new brands like this:

df['Puma'] = [[1,2,3],[0.1,0.2]]

You will obtain this dataframe:

        Nike                    Pumacount   [1, 5, 198, 0, 0, 35]   [1, 2, 3]float   [0.5, 0.3, 0.2]         [0.1, 0.2]

Then accessing the values is really simple.


You can create it like that. Type will be object.

In [254]: df=pd.DataFrame({'Brand':['Nike','Puma'],'count':[[1,2,3],[0,0]],'price':[[50.]*3,[100.]*2]})In [255]: dfOut[255]:   Brand      count               price0  Nike  [1, 2, 3]  [50.0, 50.0, 50.0]1  Puma     [0, 0]      [100.0, 100.0]