Split dataframe according to number of lines

Asked

Viewed 275 times

0

I wonder if it is possible to separate in a way a date frame of +- 300000 lines in pre-set amounts of lines and save in xlsx as the headers each part.

I thought of using Loc, but I would have to use a maximum and minimum number of rows, and I would try to do for example, every 3 rows saves the dataframe with columns.

Code:

import pandas as pd

import numpy as np

df = pd.DataFrame({'cor': ['azul', 'preto', 'amarelo', 'azul', 'preto', 'amarelo', 'preto', 'azul', 'amarelo', 'azul', 'amarelo'],
                   'preco': [1,1,1,2,3,4,5,3,2,4,1]})

df2 = df.preco

df['acumulado'] = df2.cumsum()

df

##################################
Resultado: 
    cor   preco acumulado
0   azul    1   1
1   preto   1   2
2   amarelo 1   3
3   azul    2   5
4   preto   3   8
5   amarelo 4   12
6   preto   5   17
7   azul    3   20
8   amarelo 2   22
9   azul    4   26
10  amarelo 1   27

  • You want to partition the file into smaller files?

  • That. but in a mobile amount the user will have to change. for example. every 3 x lines, save the file in xlsx.

  • he goes from the one input and that will determine the cut in the file?

  • the truncate doesn’t answer your phone?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.