Open with Pandas in Python a .xls file that is corrupted - python-3.x

So here is the problem, I'm trying to import a DF from a file downloaded from COGNOS. In cognos I select .CSV format but always is downloaded the format is .xls
It will be very easy to open the .xls file and save as CVS but the problem with that is that the file has more rows than excel so I will lose a lot of data in the process. Also when I open the file in excel it is a warning that the file could be corrupted.
When I'm trying to open the data with df = pd.read_excel("Time Series 2018-1.xls") it shows the following problem.
XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'\xff\xfeP\x00r\x00o\x00'
Please HELP

You can try
Change the file name, remove spaces and dash then try again
follow along with this pandas official link

I already resolve it. Just open the file in sublime and save with encoding UTF-8. Then just open it with df = pd.read_csv("Prueba1.xls", sep = "\t", encoding = 'utf8') because as #dougp said, is just a csv file save with the extension xls.
I guess there is a way to change the encoding in PYTHON but that's for another question.

Related

python 3.5 appending .txt file not formatting correctly when opened in notepad

I am trying to append to a text file and write on a new line each time I append the file for readability in notepad. I believe this should be simple and researched thoroughly but I am still having an issue. Here is the snippet of code that writes to a .txt file:
appending_Text = data2
with open(file_Name, 'a+') as file:
file.write(appending_Text)
file.write('\n')
When I run this code and then check the text file, I get my appended data on the same line. When I open the .txt file using notepad, I want it to look like:
data1
data2
When I open the .txt file using notepad in windows, it looks like:
data1data2
What am I missing?
I figured out the answer and it's not python related but rather a limitation of notepad in windows. Notepad uses a different new line termination than is used in linux systems. Linux uses '\n' and notepad uses '/r/n'

Cannot write british pound or euro symbols to CSV file - Nodejs

I'm writing a CSV file which contains text with british pound and euro symbols, however when I opened the file in Excel, I see some rather odd behavior. I see some weird A-looking symbol before the british pound, and quotes instead of the euro symbol. I figured it's probably because Excel doesn't like a file that's UTF8 encoded.
fs.writeFileAsync("the-file.csv", text-containing-foreing-currency, "utf8");
Does anyone know a way to get around this while creating the file? I don't want the users to have to do anything with excel after downloading the file, I just want them to be able to open the file and see the right symbols.
There shouldn't be any problem with node writing the symbols to the file, if you open it with a text editor you should see the correct characters.
The problem is with excel opening UTF8 csv files. By default it assumes ANSI encoding, so if the file is in UTF8, it scrambles the characters. You can open the file correctly with the text import wizard.
In general this is a limitation of excel. The best workaround for you will depend on your OS and Excel version. This is a heavily discussed topic, here are some good reads:
Is it possible to force Excel recognize UTF-8 CSV files automatically?
Which encoding opens CSV files correctly with Excel on both Mac and Windows?

Saving CSV in UTF-8 on Mac

I am having problems to save a CSV file for Core Data using my Mac, works if I save in Windows computer but not in the MAC. I am using Excel. Every time I run the CSV file saved in MAC there are different errors in the Xcode.
In my experience when you save CSV files in a Mac computer it is always a mess. I had several problems dug in the forums and realize only could save CSV in PC with windows. If you are using UTF-8 in your coreData you can workaround with this, I am doing this for some time and never had problem again in my Mac.The way I do:
Save the .CSV file (comma delimited) in Excel.
Open the .CSV file with (http://www.sublimetext.com/2
File > Save with Encoding > choose the one you want.
Done.
If you have to edit or open the file in Excel, you have to save in Sublime Text 2 again before you drag to your Xcode project.
Forget Windows computers :)
Hope this solve your problem.

OpenText Hijacks the File Name in Powershell

A user suggested using the OpenText command to import a pipe delimited text file into excel. The problem is, that this seems to hijack the filename and forces it to be a .txt instead of an xlsx. When I try to
-replace ".txt.*", the .txt remains and when I try to force name the file .xlsx, it just makes a "corrupt" xlsx file that won't open properly in excel.
First Question
Finding Powershell names for Excel features
.txt and .xlsx are fundamentally different file types. You can't magically convert one into the other by just renaming the file.
Going out on a limb I guess your problem is that you're trying to save the file, and $excel.ActiveWorkbook.SaveAs($y) (or whatever statement you use) doesn't create an actual workbook.
Try saving it as xlWorkbookDefault:
$excel.ActiveWorkbook.SaveAs($y, 51)

How to convert xls format to arff format?

I have a (.xls) data file and I want to use it in Weka.
I try to convert it with Weka converter as described in Weka tutorial, but after saving as .csv type I don't know how to tag the attribute or data.
Is there any other way to convert .xls format to arff?
You must work wtih csv files, they can be directly converted in command line:
java -cp "path/to/weka.jar" weka.core.converters.CSVLoader file.csv > file.arff
Please make sure that there are no quotation mark " for numeric data.
If you use non standard characters, use UTF-8 and add -Dfile.encoding=utf-8 when you start weka.
Any nominal or string data will be automatically converted
If you still have problems, please provide part of your csv file.
What do you mean by "how tag the attribute or data." ?
The following steps can solve your problem
Save your .xls file in .csv format.
Open the Weka GUI Chooser and then click on the tools button in the top menu bar.
Click on the Arffviwer
Choose file types to be loaded like, *.csv, *.data
Open *.csv file to view the data and values
Name the file with the .arff extension
Save the file

Resources