How to remove trailing commas from a CSV file?

BrentCOS

New Member
Joined
Jun 29, 2022
Messages
6
Platform
  1. Windows
Hi,

I've created a CSV file that has no header. Each row represents a customer order and each cell in that row contains an item from that order. An order can have 1 item or up to 45 items in an order. The problem is that Excel is placing a lot of commas at the end of each row and I'm trying to use the CSV file in a machine learning algorithm w/in Python and it doesn't like the commas. Any idea how to remove them? I've Googled exhaustively for a solution but nothing has worked.

What my file looks like now (Excel doesn't show you the commas but when I open the file in Notepad ++, you can see all of them (see 2nd screenshot below))

1656537428491.png



When the CSV file is opened in Notepad ++, you can see all of the commas:

1656537491973.png
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
When a csv file is generated, all rows must have the same number of fields, and this number will be based on the longest record. You could do a find and replace in Notepad++ by checking Regular Expression and replacing this

,*$

with the null string.

If you do this frequently a VBA solution could open and edit the csv file treating it as a text file.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top