Python Forum
read_csv error and rows/columns missing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
read_csv error and rows/columns missing
#6
got a good file.zip this time.

I was able to get this to run (with errors) by reducing the chunk size and a few other adjustments.
I have 32GB or memory, and a chunk size of 20,000 blew up.
if you can't get the code below to run (only one file), reduce chunk size until it does.
And don't forget, you're appending the entire file into a temporary list, so if you don't have enough memory, this will either blow up, or be stuck paging memory for a long time.
import os
import pandas as pd

# assure in proper directory
os.chdir(os.path.abspath(os.path.dirname(__file__)))

# for my test
list_raw_files = ['130000054.csv']

# Location of all files 
# file_folder = 'path_on_your_computer'
 
# # Save the files into a list (when more than 2)
# list_raw_files = [f for f in listdir(file_folder) if isfile(join(file_folder, f))]
 
# Load the right/given file
for raw_file in list_raw_files:   
     
    #  Check the file 
    if raw_file.startswith('130'): #print (raw_file)
         
        temp_list = []
        file_folder = './'
        for chunk in pd.read_csv(file_folder + raw_file, sep = ';', header = None, chunksize = 10000, error_bad_lines = False , low_memory=False):
             
            temp_list.append(chunk)
         
        data = pd.concat(temp_list, axis = 0)
         
        del temp_list
 
data.head(30)
partial error list:
Output:
b'Skipping line 10: expected 5 fields, saw 6\nSkipping line 11: expected 5 fields, saw 6\nSkipping line 13: expected 5 fields, saw 6\nSkipping line 15: expected 5 fields, saw 6\nSkipping line 17: expected 5 fields, saw 6\nSkipping line 23: expected 5 fields, saw 6\nSkipping line 24: expected 5 fields, saw 6\nSkipping line 25: expected 5 fields, saw 6\nSkipping line 27: expected 5 fields, saw 96\nSkipping line 28: expected 5 fields, saw 96\nSkipping line 29: expected 5 fields, saw 96\nSkipping line 30: expected 5 fields, saw 96\nSkipping line 31: expected 5 fields, saw 96\nSkipping line 32: expected 5 fields, saw 96\nSkipping line 33: expected 5 fields, saw 96\nSkipping line 34: expected 5 fields, saw 6\nSkipping line 35: expected 5 fields, saw 96\nSkipping line 36: expected 5 fields, saw 96\nSkipping line 37: expected 5 fields, saw 6\nSkipping line 38: expected 5 fields, saw 96\nSkipping line 39: expected 5 fields, saw 96\nSkipping line 40: expected 5 fields, saw 96\nSkipping line 41: expected 5 fields, saw 6\nSkipping line 42: expected 5 fields, saw 96\nSkipping line 43: expected 5
Reply


Messages In This Thread
RE: read_csv error and rows/columns missing - by Larz60+ - Nov-07-2019, 11:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Merging rows and adding columns based on matching index pythonnewbie78 3 992 Dec-24-2023, 11:51 AM
Last Post: Pedroski55
  Pandas read_csv markf7319 0 1,341 Mar-03-2022, 04:59 AM
Last Post: markf7319
  groupby on var with missing values error zenvega 0 1,877 May-07-2021, 07:40 PM
Last Post: zenvega
  pandas read_csv can't handle missing data mrdominikku 0 2,617 Jul-09-2020, 12:26 PM
Last Post: mrdominikku
  Checking a filename before reading it with pd.read_csv karlito 2 2,309 Oct-30-2019, 09:46 AM
Last Post: karlito
  Drop rows if a set of columns has a value dervast 1 2,063 Sep-12-2019, 04:18 PM
Last Post: sd_0912
  display graph in columns and rows william888 1 1,928 Jul-02-2019, 10:19 AM
Last Post: dataman
  utf-8 error with pandas read_csv logues 0 3,954 Oct-23-2018, 05:25 PM
Last Post: logues
  Dropping all rows of multiple columns after the max of one cell Thunberd 2 3,049 Jun-01-2018, 10:18 PM
Last Post: Thunberd
  pandas read_csv, numbers in footer mechanic310 1 2,905 May-22-2018, 10:38 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020