Skip to content

Instantly share code, notes, and snippets.

@kanazux
Last active March 22, 2018 03:56
Show Gist options
  • Save kanazux/d8cc4656af2dddf057a51a2b25c1cd6f to your computer and use it in GitHub Desktop.
Save kanazux/d8cc4656af2dddf057a51a2b25c1cd6f to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Cria um arquivo com 1000 linhas.

with open('arquivo.csv', 'a') as arq:
    for x in range(1000):
        arq.write("Linha {}\n".format(x))

Cria ums lista com as linhas do arquivo.

linhas_arquivo = open('arquivo.csv', 'r').readlines()

Gera uma nova lista agrupando os items da lista gerada pelo arquivo com 100 linhas cada grupo.

Enumera cada item do grupo e salva um arquivo identificando o novo arquivo pela posição do item no grupo.

for c, n in enumerate(list(zip(*[linhas_arquivo[i::100] for i in range(100)]))):
    with open('arquivo{}.csv'.format(c), 'a') as arq:
        for x in n:
            arq.write(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment