I've recently written a few python scripts that count the number of words in a csv file and then print as output two columns: "Prefix" and "Count" where prefix is the first word in a name in a row and count is the sum of all occurences of that name.
My question is that if I try to output to a .csv file directly, everything gets put in one column and it doesn't look nice. However, if I output first to a .txt file, and then open that file in excel such that it asks me to make a space delimiter, it looks correct. I bet the answer is pretty basic, but I'm just wondering if there is a simpler way to do this than saving as a .txt and then re-opening as a .csv. Additionally, why can I open a new excel file and open the .txt file from there and it works, whereas if I try to just "open with" the .txt file directly into excel it does not work (and instead gives me the old result with everything in one column)?
Much thanks for any help you can provide!
EDIT:
Output looks like the following when I open the .txt file as a csv with the "open with" button:
Word Count
the 333
Family 54
When I open a new excel file and open the .txt file from there and use the delimiter options that come up before the file opens, it looks correctly like this:
Word, Count
the, 333
Family, 54
CSV = comma separated values
You need to output the data separated by comma and not space. You can save this as .csv and double-click to open in excel. Then the data appears in two columns.
Additionally, why can I open a new excel file and open the .txt file from there and it works, whereas if I try to just "open with" the .txt file directly into excel it does not work (and instead gives me the old result with everything in one column)
Same reason. If you open a .txt file in excel, it will just open as text. It doesn't know how to interpret this data (what goes into which columns). When you "open a new excel file and open the .txt file from there", you are "importing" the data and you tell excel to interpret the data as two columns with space as delimiter, so it works.
You can also open the .txt file directly in excel using "open with" and then use the "Text to Columns" feature to remodel the data in a spreadsheet-friendly way.
Related
I generate some csv files using a script. Next I manually convert those csv files into excel tables using the import wizard in excel based on:
https://www.youtube.com/watch?v=z5Pxil4jVO4
Is it possible to do this automatically - e.g. by calling an excel importer from command line - so I don't need to open excel and do all the manual work?
I can open the csv file directly in Excel but its not formatted as a table. E.g. this csv file:
a,b,c
a,b,c
results in this Excel sheet:
I would like each letter to be in a separate column.
I have looked at this:
https://social.technet.microsoft.com/Forums/windowsserver/en-US/370ee470-f2cd-4f30-a167-b106dd51d47a/powershell-convert-csv-to-xlsx?forum=winserverpowershell
but its an awful lot of boiler plate code from create a simple table.
Add an extra line to your CSV file to tell Excel what the seperator is. Add the following line to the top of your CSV file:
sep=,
The easiest way, without close and edit your file - you can choose which separator you want in Excel 2010-2016 go to DATA, Text To Columns, choose Delimited, then choose your separator Comma (or other) and you will see changes immediately in the "Data preview", then click FInish.
Once you have the format you wanted, you simply save the document and it will be permanent.
I am trying to open a .dat file in excel or sigma plot. First, the file kept downloading as a PDF automatically. Then I changed the file extension to excel and also tried txt. When I try to open it from right clicking, choosing open with and then choosing excel, it doesn't give me the option to open the file as comma delimited. The data is all squished into one column with the commas still there.
How to I get my windows computer to allow me to open the file with commas delimiting so I can separate the data into cells?
Open up an instance of Excel first, then open the file from there. This should give you the dialogue to open with comma delimiting. Be sure to select "All Files" when opening the file so that .txt files are visible.
I am generating CSV files. My first row it is column names, and it looks like
User ID;First Name;Last Name;Email;...
But if I will change User ID to ID, MS office cannot open this CSV and shows me error
Cannot read record(number of record)
But this file opens correctly on, Notepad++. I am using Excel 2013. Any ideas what is wrong?
You can solve the problem by inserting the following simple text at the beginning (the first line) of your .csv file:
sep=;
This will not be seen when the file is opened in Excel. What it will do - it will explicitly tell Excel that the delimiter is ;, and values will be separated into separate cells. Also, you will be able to use ID as the title of a column. Unfortunately, I cannot answer why Excel does not like it when you use this title at the beginning of the file.
I am trying to make a CSV file from an Excel file. It has English, Korean and Japanese inputs. Right now it's saved as file.xlsx.
But when I try to save-as CSV through Excel as file.csv, all the Korean and Japanese inputs turn into question marks (???????)
I tried importing into Google Spreadsheets and exporting out as csv from there (from reading some other solutions) but it still turns into question marks.
I tried building a CSV file from scratch and just copying/pasting values from the Excel file into the CSV, but after I save it as CSV, the characters always crack.
Does anybody know how to work-around this? Thank you
I don't know that there IS an answer for this. CSV has no encoding, so it gets lost when you save in that format.
I tried, as a test, saving Chinese characters as a Unicode Text file, and believe it or not, that worked. So you may be able to do that, and simply change the filename to CSV. Assuming for some reason you NEED the filename to be CSV.
EDIT: I just ran addional testing on this. I was able to reimport the TXT file with either TXT or CSV extension, and the characters stayed just fine. So I think Unicode text is your answer.
Simply opening a CSV file in Excel only works when default assumptions hold. You may be writing the CSV correctly but not validating it properly.
It is more reliable to open a blank worksheet and then use Data Import. The encoding of the CSV file is one of the parameters you can specify.
To fully retain the characters while saving it on a CSV format and to somehow be able to import/re-use the data in the future.
You can follow these steps.
In Microsoft Excel, open the *.xlsx file.
Select Menu | Save As.
Enter any name for your file.
Under "Save as type," select Unicode Text.
Click Save.
Open your saved file in Microsoft Notepad.
Replace all tab characters with commas (",").
Select a tab character (select and copy the space between two column headers)
Open the "Find and Replace" window (Press Ctrl+H) and replace all tab characters with comma .
Click Save As.
Name the file, and change the Encoding: to UTF-8.
Change the file extension from .txt to .csv.
Click Save.
Open the .csv file in Excel to view your data.
Had the same issue. the below article shows the workaround in details:
https://help.salesforce.com/articleView?id=000003837&type=1
However, i decided to go with LibreOffice Calc, as it requires less steps to achieve the desired outcome. While exporting, you get to select charecter set, field delimiter and text decimeter.
For all other tasks, i prefer Excel.
Download and install Unicode CSV Addin for excel.
Save the csv from the new "Unicode CSV" menu as shown in picture
below.
I have a text file with a list of usernames, and I have an excel file with about 4000 rows and about 9 columns. Basically what I'm looking to do is find any instance of anything from the TXT file in the Excel file. The match might not be EXACTLY the same, like :
TXT file has a row monkey1
excel file has a cell in column "C" with \\server1\monkey1
I would like to somehow flag that cell, or even the line in the TEXT file, or a seperate output.
I'm also pretty flexible on how to do this, like VBA/Macros etc. Or even putting this into an Access database or something similar. Or even converting the TXT to CSV or the Excel to another format.
Any advice would be greatly appreciated, or any guidance on what I should be looking for.
Thanks!
Export as csv
Write a python script that reads the csv with the csv module;
and the text file;
and then appends a magic string, like !! to each cell containing the text of a line from the text file;
then outputs a csv file with the updated table;
Then you can import it in excel;
And format-search-and-replace !! into a formatting of background color.