I need to automate the import a few large text files into my python script for some data wrangling and analysis. I need to remove/remedy specific instances of non-printable characters in order to stop pandas read_csv() splitting strings into new rows. I'm using Jupyter Notebook 5.0.0 and this is the latest version I will have available.
I have multiple text files with 800,000+ rows of strings over 500 characters in length. These strings contain an array of characters some of which are being handled in an undesirable way due to the insertion of '\n' mid string for some rows.
I have got round this problem using PowerShell to run against each file as a short-term manual fix using the following code:
#Encoding Unicode
(Get-Content file.txt -Raw).replace('`nabc', 'abc') | Set-Content Newfile.txt
I've tried using the open(filename.txt, 'rb').read()
method with line by line outputs but the data feed is too large. I have increased the data feed in the jupyter_notebook_config.py file incrementally but it just ends up making Jupyter unresponsive and crashes without producing the goodies.
I have tried:
import pandas as pd
pd.read_csv('filename.txt', sep='\t', header=None, linetermintator='~', encoding='utf-16')
Basically the text file has already split the row at the '\n' point, pandas won't override the format or read it as raw.