Skip to content Skip to sidebar Skip to footer

Table, With The Different Length Of Columns

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

Solution 1:

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)

Post a Comment for "Table, With The Different Length Of Columns"