深度阅读

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

作者
作者
2023年08月22日
更新时间
9.91 分钟
阅读时间
0
阅读量

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.

相关标签

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。