How to split and save a DataFrame

It is possible to specify the number of rows per DataFrame by specifying the value of k below.

k = 10000  #Number of rows per DataFrame
dfs = [df.loc[i:i+k-1, :] for i in range(0, len(df), k)]
for i, df_i in enumerate(dfs):
    fname = str(i) + ".csv"
    df_i.to_csv(fname)

Recommended Posts

How to split and save a DataFrame
[Python] How to add rows and columns to a table (pandas DataFrame)
How to get a specific column name and index name in pandas DataFrame
How to call a function
How to hack a terminal
How to display DataFrame as a table in Markdown
[Python] How to split and modularize files (simple, example)
How to save a table scraped by python to csv
[TF] How to save and load Tensorflow learning parameters
How to manage a README for both github and PyPI
[Python] Summary of how to use split and join functions
[TF] How to load / save Model and Parameter in Keras
How to write a metaclass that supports both python2 and python3
How to make a Japanese-English translation
How to put a symbolic link
How to install and use Tesseract-OCR
How to make a slack bot
How to create a Conda package
How to make a crawler --Advanced
How to make a recursive function
How to create a virtual bridge
How to install and configure blackbird
How to use .bash_profile and .bashrc
How to install CUDA and nvidia-driver
How to install and use Graphviz
How to make a deadman's switch
How to create a Dockerfile (basic)
[Blender] How to make a Blender plugin
How to delete a Docker container
How to make a crawler --Basic
How to create a config file
How to solve slide puzzles and 15 puzzles
How to interactively draw a machine learning pipeline with scikit-learn and save it in HTML
How to set a shortcut to switch full-width and half-width with IBus
How to build a LAMP environment using Vagrant and VirtulBox Note
Overview of how to create a server socket and how to establish a client socket
How to compare lists and retrieve common elements in a list
[Introduction to Python] How to split a character string with the split function
Process Splunk execution results using Python and save to a file
How to make a surveillance camera (Security Camera) with Opencv and Python
JOI2019 / 2020 1st qualifying 3rd How to solve problems A and B
[C language] How to create, avoid, and make a zombie process
How to find the memory address of a Pandas dataframe value
How to format a table using Pandas apply, pivot and swaplevel
How to save only a part of a long video using OpenCV
How to create a clone from Github
[Linux] How to subdivide files and folders
How to package and distribute Python scripts
How to build a sphinx translation environment
How to create a git clone folder
Qiita (1) How to write a code name
How to install and use pandas_datareader [Python]
How to add a package with PyCharm
[Python] How to make a class iterable
How to draw a graph using Matplotlib
[Python] How to convert a 2D list to a 1D list
[Colab] How to copy a huge dataset
[Python] How to invert a character string
How to install a package using a repository
[Ubuntu] How to execute a shell script
How to get a stacktrace in python