bern_code
bern_code

Reputation: 61

How to read a group of elements in pandas?

I trying to create a code to take all my data and create groups/DF. For example, I have 4000 rows in my data but I want to read the first 100 and create a DataFRAME with this first 100, read the next 100 and create a another DataFRAme until the EOF.

I started with that but I just can take all the data:

for index, rows in df_.iterrows():
   # Create list for the current row
   my_list = rows.Temperatura

   # append the list to the final list
   Row_list.append(my_list)

Upvotes: 0

Views: 36

Answers (1)

Ahmad
Ahmad

Reputation: 72613

You can numpy's array_split:

In [1]: import pandas as pd
In [2]: import numpy as np
In [3]: df = pd.DataFrame(list(range(1000)))
In [4]: np.array_split(df, df.count() / 100)

Upvotes: 1

Related Questions