0

I have a very large Dataframe with more than 3000 columns. Column names starts with items_0_**** | items_0_**** | items_1_**** | items_1_**** and so on up to items_99_*** . I want to Split my Large DataFrame in such a way that items_0_*** in one Dataframe, items_1_**** in one Dataframe and so up to items_99_**** in one DataFrame.

So Finally I need to get 100 Data Frames.

Column names starting with items_0_ must be in one Dataframe.
Column names starting with items_1_ must be in another Dataframe.
.

.

.

Column names starting with items_99_ must be in another Dataframe.

Any help is appreciated.

2
  • How do you want to retrieve your dataframes, from a dict? Commented Jan 2, 2020 at 10:09
  • Updated my Question, Please check. Commented Jan 2, 2020 at 10:16

1 Answer 1

1

How do you want to retrieve your dataframes, from a dict?

If so:

my_dataframes = dict()

for i in range(100):
    my_dataframes[i] = df[[j for j in df.columns if j.startswith(f'items_{i}_')]]

Then, if you type my_dataframes[0], you'll get a dataframe with the columns items_0_****

Sign up to request clarification or add additional context in comments.

3 Comments

Is there any way to store each of them in different csv files?
You could put them all in a list, I guess? What do you want to do with them, once you have all your difference dataframes?
After I get all the different DataFrames , I need to merge them into one single DataFrame again, For Example : Columns items_0_a , items_1_a, items_2_a values should be in one single column.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.