I am not sure I can ask this below question here.
I generated a CSV file. Each CSV line contains a field in this format {digits}-{digits} such as 4-48, 5-62, ...
When I open the CSV file using Microsoft Excel. I got Apr-48 ( for 4-48) and May-62 (for 5-62)
Anyone has any ideas? I expected what I can see in excel is 4-48, 5-62. I already tried to format the column already. I used general format OR Text format but It didn't work.
Thank you!
You can import the csv into Excel from Data > From Text then go through the wizard and import the columns as text (on step 3 of the wizard) and then excel should not try and be "clever" and covert them to a date.
Related
Pandas DataFrames - how do I export list 'X' to a CSV so it appears as a string? The problem is when I open the CSV using Excel it appears in date format.
X=['1-4', '1-5', '2-3', '4-8']
ie. when list 'X' is exported to a CSV and opened with Excel it appears as a date:
I would like list 'X' to appear in Excel as is - that is, not converted it to date format.
Desired output for Excel is:
I have tried the following code - but it throws an error:
import pandas as pd
X=['1-4', '1-5', '2-3', '4-8']
Y=[1,4,3,5]
df=pd.DataFrame(list(zip(X,Y)))
column_names=['A','B']
df.columns=[column_names]
df.A.to_string()
df.to_csv('yyy.csv', mode='a', header=True)
Thankyou
worked fine with me...
maybe the excel or whatever program u use to open the file is casting it... try open it as text file...
Even if Excel reads in date format, when you open in pandas it will come in original format (at least in my case). If someone only wants to save data in csv and work in pandas again, it should be fine.
I also tried doing the 2nd option here (https://www.winhelponline.com/blog/stop-excel-convert-text-to-number-date-format-csv-file/) which transform the data as text. And then saving again. It worked for me.
I am having problems converting an MSaccess table that contains a 12 digits barcode-number field to CSV file
The barcode field is defined as text!
I tried exporting to Excel and saving the Excel file to CSV or exporting it to CSV But but that did not work either (even when the field is defined as text).
The problem is that some barcodes start with zero which gets truncated and that displays a scientific notation instead of displaying the barcode string.
My Question is: How can I generate a CSV file that is stored as an Excel spread sheet?
any help is appreciated
Dory
Nick McDermaid thanks for your comment. When looking in a text editor everything looks perfect.....You mean the people requesting it on my website are actually using it as text file and do not care about the way it looks in a spread sheet? if so then I am just chasing a wild goose! is that what you mean?
I have a .csv file that is created generated using some legacy software. There is no way to look inside the code at how or what its doing to produce the csv file.
My issue is that the date field format is behaving strangely.
The .csv file is storing the date in the following format.
MM-dd-yyyy HH:mm:ss.SSS
Looking in the file in notepad (raw data) we get a list of columns like this:
"01-12-2013 14:23:38.000",146.199997
"01-12-2013 23:20:29.000",146.199997
"01-13-2013 17:59:23.000",152.299988
"01-13-2013 18:08:40.000",147.300003
"01-13-2013 18:25:52.000",156.000000
"01-13-2013 18:35:14.000",146.300003
"01-13-2013 18:44:56.000",148.500000
"01-13-2013 18:56:41.000",151.699997
NOTE: I have stripped out the remaining columns to make it easier on the eye so we are only seeing the first 2 columns in the .csv file.
Now when I open this file in Excel 2010 version 14.0.6023.1000 (32-bit) I get date format problems.
Firstly if I just open the file I get blocks of mixed date formatting like this:
And this:
I can see that Excel is getting confused when the day value is switching from 12 to 13. If i then try to change the formatting to fix the issue using the following cell formatting settings:
Then I get the following displayed in the column when the day is less than 13:
And the following format when the day is greater than or equal to 13:
Any help would be really appreciated on this as I am now completely out of ideas.
NOTE: I have also tried copying the contents of the .csv file into another file but the same things occur in the new file.
This problem is to do with how Excel is interpreting the date format (M/D/Y vs. D/M/Y). It appears your system is setup for D/M/Y date formats. You won't find the setting in Excel because it derives it from your system settings. Go to the Language settings and add US English. Then set it to default and try opening the CSV file again.
Alternatively you can paste the csv file contents into a new sheet and use the 'Text-to-Columns' feature, which will let you specify the date format.
You have a conflict between the format of the .csv and your Regional settings.
First import the data as Text,(rather than double-clicking). Then in B1 or some other column enter:
=DATE(MID(A1,8,4),MID(A1,2,2),MID(A1,5,2))+TIMEVALUE(MID(A1,13,8))
and apply the desired formats:
I found a work around for my instance after reading the answers from #Gary's Student and #hughg. Thanks for the ideas.
So to fix my issue:
Modified my regional settings for dates and times to US.
Opened the file as normal in excel.
Selected the column in question and formatted cells into text. This converted all the dates in the file into floating point numbers.
Finally Apply following custom format to the cells: dd/mm/yyyy hh:mm:ss
The result is that every date in the file is now correctly formatted into UK date format.
A 3rd party software 'Eclipse Orchestrator' saves its config file as 'csv' format. Among other things it includes camera exposure times like '1/2000' to indicate a 1/2000 sec exposure. Here a sample line from the csv file:
FOR,(VAR),0.000,5.000,49.000
TAKEPIC,MAGPRE (VAR),-,00:01:10.0,EOS450D,1/2000,9.0,100,0.000,RAW+FL,,N,Partial 450D
ENDFOR
When the csv file is loaded into Excel the screen display reads 'Jan-00'. So Excel interprets the string 1/2000 as a date. When the file is saved again as csv and inspected in an ascii editor it reads:
FOR,(VAR),0,5,49,,,,,,,,
TAKEPIC,MAGPRE (VAR),-,01:10.0,EOS450D,Jan-00,9,100,0,RAW+FL,,N,Partial 450D
ENDFOR,,,,,,,,,,,,
I had hoped to use Excel to variablearize the data and make it easier changeable. But the conversion to fake dates is not helping here.
The conversion at load-time affects the saved data format making it then unreadable for the 'Eclipse Orchestrator' program.
Any way to save the day in Excel, or just move on to write a prog to do the patching of the csv file?
Thanks,
Gert
If you import the CSV file instead of opening it, you can use the import wizard (Data ribbon > From Text) to define the data type of each column. Select Text for the exposure time and Excel will not attempt to convert it.
I am reading a CSV file using SSIS tool but problem is that data which I read is in wrong format means to say data of columns mismatch. Like Note column data which contains message comes in Id column etc. I tried all types of separator and text qualifier but did't help me.
Main problem is that excel is able to show data in correct format but SSIS is not. I want to know why it is happen or I am missing something.
Any help or suggestion is greatly appreciated.
Thanks.
If its a csv file, do not open in Excel. Use a Wordpad(preferable) or a notepad to view the data. Find out what the delimiter is and give it a try. That might help you out.