Home > OS >  How to write semicolon separated value in one csv column?
How to write semicolon separated value in one csv column?

Time:05-30

I write with python automated names to a CSV file. However, I have the problem that I include names that are separated with a semicolon. Therefore, names that are separated with a semicolon are written in two columns although I want to have them only in one.

product_data= product_data   ";"   re.search(r">(.*?)</", i).group(1)

Within the the re.search() function I filter names which are between "> <". The code works but as described above, I want names to be written in one column and not in two.

CodePudding user response:

I'm not entirely sure if I fully understand the question, but let me attempt to answer it. CSV files just require some time of character to serve as the delimiter that divides each column in a row. What if instead of using a semi-colon as a delimiter you used a comma or, if that appears somewhere in names or product_data perhaps you could use "|"? Additionally, if you wanted to remove the semicolon from the names, you could turn re.search(r">(.*?)</", i).group(1) into "".join(re.search(r">(.*?)</", i).group(1).split(";")). Hope this helps!

  • Related