When i try to open space delimited file in excel, the whole content opens in a single column. Is there any way to open the space delimited file in excel so that the delimited contents are properly formatted into different columns?
My scenario is that i have a file that needs the delimiter to be some thing like '" ' (A inverted command followed by a space), because my file format is like this:
"First Name" "Gender" "Phone"
"Tom Jones" "M" "123-123-1234"
To open a comma-delimited (CSV) file properly, use Excel's Data Import from Text feature to open the import wizard and set all columns as text. If you click the file and allow Excel to open it automatically, the columns might be formatted improperly.
The most straightforward way to convert a space-delimited to a comma-separated (CSV) file in Python is to replace each empty space ' ' with a comma ',' character using the string. replace() method. This works if two values are separated by exactly one empty space.
I think you can specify the string quotation mark('
, "
or none) in the wizard, in the same step where you specify the delimiter.
"
. Then Excel will recognise the string quoted in " "
and separate in columns the data with space. Note: be sure that all the delimiter is one space; several spaces will be divided into several columns. To avoid that, please preprocess the csv
file with a text editor. Sublime Text/Notepad++ will do. To make is more clear, I always substitute the delimiter with ;
.
Replace multiple (more than one) spaces with ;
: find \s\s*
and replace with ;
. Change by need.
Use the standard "Open" command. Then go to "Text Import Wizard" and choose that the original data type was delimited. You may need to go to a different step of the Wizard to specify that the delimiter is a space, but the Wizard does include the option of specifying what character the delimiter is.
On the Data tab click on From Text in the Get External Data section.
Tell the Wizard to use the space as the delimiter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With