Python Forum
Remove single and double quotes from a csv file in 3 to 4 column
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remove single and double quotes from a csv file in 3 to 4 column
#1
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.[Image: view?usp=sharing]

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. [Image: view?usp=sharing]

Attach csv file CSV File
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help copying a column from a csv to another file with some extras g0nz0uk 3 403 Feb-01-2024, 03:12 PM
Last Post: DeaD_EyE
  How to read csv file update matplotlib column chart regularly SamLiu 2 1,016 Jan-21-2023, 11:33 PM
Last Post: SamLiu
  Need help on how to include single quotes on data of variable string hani_hms 5 1,886 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  python Multithreading on single file mg24 3 1,671 Nov-05-2022, 01:33 PM
Last Post: snippsat
  Create multiple/single csv file for each sql records mg24 6 1,323 Sep-29-2022, 08:06 AM
Last Post: buran
  Read xml column inside csv file with Python estertabita 2 1,327 Jul-26-2022, 06:09 PM
Last Post: Larz60+
  Reshaping a single column in to multiple column using Python sahar 7 1,968 Jun-20-2022, 12:35 PM
Last Post: deanhystad
  Transform 3 Columns into Single Column DaveG 8 1,801 Apr-04-2022, 08:42 AM
Last Post: Pedroski55
  How to split file by same values from column from imported CSV file? Paqqno 5 2,705 Mar-24-2022, 05:25 PM
Last Post: Paqqno
  Appending Excel column value as CSV file name sh1704 0 1,268 Feb-06-2022, 10:32 PM
Last Post: sh1704

Forum Jump:

User Panel Messages

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