python - Modifying large csv in chunks? -


I get an error in 'TypeError:' TextFileReader does not support 'object item assignment' when I add columns and headers to

My problem is that I am using a slow working laptop to process a very large file (10 million lines). I want to add some simple columns (1 or 0 values), add two columns to create a unique ID, change the DTP type for other columns, and change the name of some headers, so that they match the other files Are I. I could probably split this CSV (maybe select date date and make different files), but I would like to know how to select or deal with large files without running in memory issues. Is it possible to modify windows in the file and then insert them together later?

I am cleaning a raw data that will be loaded into the plateau for the scene.

Example (10 million lines read / modify):

  & gt; rep = pd.read_csv (r'C: \ repeats.csv.gz ', & gt; compression =' gzip ', parse_dates = true, usecols = & gt; [' etc ',' content ',' other ',' .. '.]] & Gt; Rep.sort () & gt; Representative ['total_start'] = 1 & gt; Rep.rename (column = {'X': 'Y'}, inplace = true)> Rep.rename (column = {'Z': 'A'}, inplace = true)> Rep.rename (column = {'B': 'C'}, inplace = true)> Representative ['de'] = representative ['e'] + delegate ['c'] & gt; Rep.rename (column = {'L': 'M'}, inplace = true)> Rep.rename (column = {'n': 'o'}, inplace = true)> Rep.rename (column = {'s': 't'}, inplace = true)    

Python is usually very good with that unless you ignore it. Reed () part when viewing large files

If you use the easter only, then you should be OK: > mybiginputfile.txt', 'rt') with pre-> Out_file as Open ('mybigoutputfile.txt', 'wt'): For row in in_file: 'do something' out_file.write (line)

No one knows more, It will tell about how memory side works about it, but it works for me without crashing Python on multiple GB files.

Even after slipping data into a proper DB before hitting the data with your data, kill your laptop! Even << p>

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -