Split a Pandas Dataframe into multiple Dataframes based on Triangular Number Series

Tylerr

I have a DataFrame (df) and I need to split it into n number of Dataframes based on the column numbers. But, it has to follow the Triangular Series pattern:

df1 = df[[0]]
df2 = df[[1,2]] 
df3 = df[[3,4,5]]
df4 = df[[6,7,8,9]]

etc.

piRSquared

Consider the dataframe df

df = pd.DataFrame(
    np.arange(100).reshape(10, 10),
    columns=list('ABCDEFGHIJ')
)

df

    A   B   C   D   E   F   G   H   I   J
0   0   1   2   3   4   5   6   7   8   9
1  10  11  12  13  14  15  16  17  18  19
2  20  21  22  23  24  25  26  27  28  29
3  30  31  32  33  34  35  36  37  38  39
4  40  41  42  43  44  45  46  47  48  49
5  50  51  52  53  54  55  56  57  58  59
6  60  61  62  63  64  65  66  67  68  69
7  70  71  72  73  74  75  76  77  78  79
8  80  81  82  83  84  85  86  87  88  89
9  90  91  92  93  94  95  96  97  98  99

i_s, j_s = np.arange(4).cumsum(), np.arange(1, 5).cumsum()

df1, df2, df3, df4 = [
    df.iloc[:, i:j] for i, j in zip(i_s, j_s)
]

Verify

pd.concat(dict(enumerate([df.iloc[:, i:j] for i, j in zip(i_s, j_s)])), axis=1)

    0   1       2           3            
    A   B   C   D   E   F   G   H   I   J
0   0   1   2   3   4   5   6   7   8   9
1  10  11  12  13  14  15  16  17  18  19
2  20  21  22  23  24  25  26  27  28  29
3  30  31  32  33  34  35  36  37  38  39
4  40  41  42  43  44  45  46  47  48  49
5  50  51  52  53  54  55  56  57  58  59
6  60  61  62  63  64  65  66  67  68  69
7  70  71  72  73  74  75  76  77  78  79
8  80  81  82  83  84  85  86  87  88  89
9  90  91  92  93  94  95  96  97  98  99

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Pandas - Split dataframe into multiple dataframes based on dates?

From Dev

Split a Pandas Dataframe into multiple smaller dataframes based on empty rows

From Java

Split pandas dataframe into multiple dataframes based on null columns

From Dev

Split pandas dataframe into multiple dataframes based on null columns

From Dev

Split one dataframe to multiple sub-dataframes based on common columns in Pandas

From Dev

Split pandas dataframe column based on number of digits

From Dev

Split a pandas dataframe into two dataframes efficiently based on some condition

From Dev

Split pandas dataframe into multiple dataframes with equal numbers of rows

From Dev

Pandas Split Dataframe into two Dataframes

From Dev

Separating a dataframe into multiple dataframes based on the index value in pandas

From Dev

Split Pandas Series into DataFrame by delimiter

From Dev

Split Pandas Series into DataFrame by delimiter

From Dev

pandas: Convert Series of DataFrames to single DataFrame

From Java

How to split dataframe into multiple dataframes by column index

From Dev

Split pandas dataframe based on groupby

From Dev

pandas: Split separated values in a DataFrame column (one Series) into multiple Columns. Elegant solutions?

From Java

Create a dataframe based in common timestamps of multiple dataframes

From Dev

Create A New DataFrame Based on Conditions of Multiple DataFrames

From Dev

How to split a pandas series with multiple options?

From Dev

Joining two pandas dataframes based on multiple conditions

From Dev

Change dataframe pandas based one series

From Dev

Change dataframe pandas based one series

From Dev

How to change specific cell values in a pandas dataframe column series based on multiple conditions?

From Dev

how to split 'number' to separate columns in pandas DataFrame

From Dev

How to split a pandas dataframe based on column prefix

From Dev

Split Python Dataframe into multiple Dataframes (where chosen rows are the same)

From Dev

Split dataframe to several dataframes

From Dev

mapping dataframes not series pandas

From Dev

pandas concatenating dataframes and series

Related Related

  1. 1

    Pandas - Split dataframe into multiple dataframes based on dates?

  2. 2

    Split a Pandas Dataframe into multiple smaller dataframes based on empty rows

  3. 3

    Split pandas dataframe into multiple dataframes based on null columns

  4. 4

    Split pandas dataframe into multiple dataframes based on null columns

  5. 5

    Split one dataframe to multiple sub-dataframes based on common columns in Pandas

  6. 6

    Split pandas dataframe column based on number of digits

  7. 7

    Split a pandas dataframe into two dataframes efficiently based on some condition

  8. 8

    Split pandas dataframe into multiple dataframes with equal numbers of rows

  9. 9

    Pandas Split Dataframe into two Dataframes

  10. 10

    Separating a dataframe into multiple dataframes based on the index value in pandas

  11. 11

    Split Pandas Series into DataFrame by delimiter

  12. 12

    Split Pandas Series into DataFrame by delimiter

  13. 13

    pandas: Convert Series of DataFrames to single DataFrame

  14. 14

    How to split dataframe into multiple dataframes by column index

  15. 15

    Split pandas dataframe based on groupby

  16. 16

    pandas: Split separated values in a DataFrame column (one Series) into multiple Columns. Elegant solutions?

  17. 17

    Create a dataframe based in common timestamps of multiple dataframes

  18. 18

    Create A New DataFrame Based on Conditions of Multiple DataFrames

  19. 19

    How to split a pandas series with multiple options?

  20. 20

    Joining two pandas dataframes based on multiple conditions

  21. 21

    Change dataframe pandas based one series

  22. 22

    Change dataframe pandas based one series

  23. 23

    How to change specific cell values in a pandas dataframe column series based on multiple conditions?

  24. 24

    how to split 'number' to separate columns in pandas DataFrame

  25. 25

    How to split a pandas dataframe based on column prefix

  26. 26

    Split Python Dataframe into multiple Dataframes (where chosen rows are the same)

  27. 27

    Split dataframe to several dataframes

  28. 28

    mapping dataframes not series pandas

  29. 29

    pandas concatenating dataframes and series

HotTag

Archive