0

How do divide pandas dataframe in other blocks of data?

Attention: I don't want to do multiple queries to the database. I already have the query result in the desired size. What I need is to break the resulting dataframe into smaller dataframes.

I am start learn to work with pandas and try make a division of datas from a dataframe. I connect to SQL Server using pyodbc and get data with pandas.read_sql(...). The result is aproximately 5000 records. I need fragment the dataframe in blocks of 50 records without a loop (while, for, etc). I am convert the dataframe in dictionary and I am trying use compreension, but I don't have success:

[x for x in original_dataframe[:int(len(original_dataframe)/50)]

I need a result a blocks of other dicts or dataframes, e.g.:

block_01 = original_5000_records[:50]
block_02 = original_5000_records[50:100]

etc.

I yet do not understand weel, but I believe that is possible to use pandas.shape() or pandas.iloc(), maybe there are the way. Someone can helpe me to make and compreend this? Thanks.

GustavoAdolfo
  • 361
  • 1
  • 9
  • 23

0 Answers0