Mar-31-2021, 10:52 AM
If I did not read csv like this then it will give tokenizing error. But when I read like this in some column double quotes are appearing. I need to remove them. Double quotes look this, see attached picture.
Attach csv file CSV File
csv_files=['BK00018384.CSV'] from pathlib import Path import time import pandas as pd import numpy as np import datetime df=pd.DataFrame() for fn in csv_files: all_dfs = pd.read_csv(fn,header=None, sep='\n') all_dfs = all_dfs[0].str.split(',', expand=True) all_dfs[1] = all_dfs[1].apply(lambda x: x.replace('"', "")) all_dfs[2] = all_dfs[1].apply(lambda x: x.replace('"', "")) all_dfs[3] = all_dfs[1].apply(lambda x: x.replace('"', "")) all_dfs[4] = all_dfs[1].apply(lambda x: x.replace('"', "")) all_dfs[4] = all_dfs[1].apply(lambda x: x.replace('-', ""))
Error: 1 pd.set_option("display.max_rows", None, "display.max_columns", None)
----> 2 all_dfs[1] = all_dfs[1].apply(lambda x: x.replace(r'"', ""))
3 #all_dfs.apply(lambda x: x.str.replace('"-"', ""))
4 all_dfs.to_csv('Test.csv', index=False)
AttributeError: 'NoneType' object has no attribute 'replace'
Want to remove this double quotes. Attach csv file CSV File