How to fix csv "field larger than field limit (131072) " in python

Published on Aug. 22, 2023, 12:20 p.m.

The “field larger than field limit (131072)” error occurs when a field (a single cell in the CSV file) exceeds the default field limit, which is set to 128 * 1024 = 131072 bytes in Python. To fix this error, you can increase the field_size_limit by importing the sys module and setting the field_size_limit to sys.maxsize, which should remove the limit on field size. Here is an example:

import csv
import sys

csv.field_size_limit(sys.maxsize)

Alternatively, you can set the field_size_limit to a specific value that is larger than the largest field in your CSV file. For example, if the largest field in your CSV file is 200,000 bytes, you can set the field_size_limit to 200000:

import csv

csv.field_size_limit(200000)

It’s important to note that increasing the field size limit may cause performance issues or memory errors if the CSV file contains very large fields. In that case, you may need to consider alternative methods for processing the data.

Tags:

csv