Reputation: 4023
I have some list of items:
list = [1, 2, 3, 4, 5, ...... 2, 7, 4, 9, .....]
Now I need to create such table with the specific fix number of columns. My code should have next logic:
list
list
into specific column of my table. Consequently, at the end, the length of column in this table (or DF) should be different for all columns.Some first solution is to create another lists and just put the values into the lists. At the end I can normalize the length of lists (for example with some values like NaN
) and create from these lists DF.
Probably somebody can say me better solution...
For example I try to do it with the pandas DF, but I don't want add the whole row, just unique value into specific column.
Upvotes: 0
Views: 1030
Reputation: 97331
You can use groupby.cumcount()
and pivot()
, here is an example:
import numpy as np
import pandas as pd
numbers = np.random.randint(0, 1000, 100)
col = numbers % 4 # put your logic here
s = pd.Series(numbers)
cnt = s.groupby(col).cumcount()
pd.pivot(cnt, col, numbers)
Upvotes: 1