cannot use LOCALE flag with a str pattern - python-3.x

import xlwt
wb = xlwt.Workbook()
sheet1 = wb.add_sheet('Sheet 1')
wb.save('self, example.xls')
I am trying to learn how to create xls, edit xls, or delete if neccesary on python. I had verymuch trouble on this because every tutorial online doesn't mentions that I should put xlwt before Workbook but I figure it out now. The problem is when I run this code I get an error wich it says "ValueError: cannot use LOCALE flag with a str pattern" I don't even know what that means... What is it about and how can I fix it?

There is a known-issue with tablib and Python 3.6, looks like it will be solved in the next releases.
For now, I make it work just downgrading to python 3.5.2

I had a similar problem and i resolved it by changing my series to "str" data type. df.astype("str")
Also not sure why you are trying to save your file as "self, example.xls". Could you print the entire error as it was given.

Related

What are Python3 libraries which replace "from scikits.audiolab import Format, Sndfile"

Hope you'll are doing good. I am new to python. I am trying to use audio.scikits library in python3 verion. I have a working code version in 2.7(with audio.scikits) . While I am running with python3 version I am getting the Import Error: No Module Named 'Version' error. I get to know that python3 is not anymore supporting audio.scikits(If I am not wrong). Can anyone suggest me replacing library for audio.scikits where I can use all the functionalities like audio.scikits do OR any other solution which might helps me. Thanks in advance.
2.7 Version Code :
from scikits.audiolab import Format, Sndfile
from scipy.signal import firwin, lfilter
array = np.array(all)
fmt = Format('flac', 'pcm16')
nchannels = 1
cd, FileNameTmp = mkstemp('TmpSpeechFile.wav')
# making the file .flac
afile = Sndfile(FileNameTmp, 'w', fmt, nchannels, RawRate)
#writing in the file
afile.write_frames(array)
SendSpeech(FileNameTmp)
To check entire code please visit :Google Asterisk Reference Code(modifying based on this code)
I want to modify this code with python3 supported libraries. Here I am doing this for Asterisk-Microsoft-Speech To Text SDK.
Firstly the link code you paste is Asterisk-Google-Speech-Recognition, it's not the Microsoft-Speech-To-Text, if you want get a sample about Microsoft-Speech-To-Text you could refer to the official doc:Recognize speech from an audio file.
And about your problem you said, yes it's not completely compatible, in the github issue there is a solution for it, you could refer to this comment.

python - how to delete a row in DictReader

I am sometimes using Python for some automation stuff. I just came around a Problem I am not able to solve.
I use Python 3.3.
I have a .csv file opened as a DictReader. Now I want, depending on a condition, to delete a row in the DictReader.
The code looks pretty much like:
reader = csv.DictReader(csvfile, delimiter = ";")
...
if True:
del reader[row]
Well, Python tells me that: "the dictReader object does not support item deletion".
Something there I am totally missing? Is there a built-in way to do it and I just did not find it in the manual, or do I have to use some kind of workaround?
best regards,
moritz

error uploading csv file on cloud jupyter notebook

I have set up a google cloud account
I want to perform my deep learning much more faster on a jupyter notebook, but
I cannot find a way to read my csv file
I downloaded it with wget from my github account and afterwards I tried
dataset = pd.read_csv('/home/user/.jupyter/SIEMENSTRAIN.csv')
but I get the following error
pandas.parser.CParserError: Error tokenizing data. C error: Expected 2 fields in line 3, saw 12
Why? When I read it on my laptop using my jupyter notebooks, everything runs well
Any suggestions?
I tried the recommended solutions for this error and I got the next warning
/home/user/anaconda3/lib/python3.5/site-packages/ipykernel/main.py:1: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators; you can avoid this warning by specifying engine='python'.
if name == 'main':
When I ran dataset.head() this is what appeared
Any help please?
There are a number of possibilities that could be causing the problem... I would first always make sure that Pandas (pd)'s version is updated and compatible.
The more likely cause is that the CSV itself is not right, so pd.read_csv() is not able to work correctly (thus a Parse Error). This may have something to do with the headers, though I'm not sure what your original CSV file looks like. It's worth playing around with read_csv, for example:
df = pandas.read_csv(fileName, sep='delimiter', header=None)
This tampers with 2 things - the delimiter, and if pd is reading a header from CSV or not.
I go through some pd.read_csv() stuff in my book about Stock Prediction (another cool Machine Learning problem) and Deep Learning, feel free to check it out.
Good Luck!
I tried what you proposed and this is what I got
So, any suggestions?
I suppose that the path is ok, but it just won't be read properly, or am I wrong?

python win32 error,Microsoft Excel',

my last part of code is as follows;
from openpyxl import Workbook
import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')
for wb in excel.Workbooks:
if wb.Name[:10] == 'da_woprint' :
print('yes')
import os
os.chdir('C:\\Users\\maliadil\\Desktop')
wb.SaveAs(r'C:\Users\maliadil\Desktop\{0}.xls'.format(r))
excel.Application.Quit()
browserchr3.quit()
I have automated my chrome to use one of my Maximo web application to do some task and get the daily report which comes out in excel (.xls)format.I was able to do the whole thing,except the last step,which is nothing but saving this excel file,in a directory using a variable "r"(which contain previous day's date in string format),in which I am getting the error.But I am able to save it with a static name`.
Judging from your comment:
What I think you want is that the 5 is replaced with a variable.
In your case you want it to be stored in variable r. (This is not a very good name by the way).
So what you need to do is to inject your variable into your string somehow. There are a couple of ways to do this.
The first way is my favorite:
r = 5
wb.SaveAs('C:\Users\maliadil\Desktop\{0}.xls'.format(r))
You could also use %s to make this case work and a couple of other things, for more info, here
If you want to store the whole string, what you may want to do, I still don't really understand the case, is the following:
r = 'C:\Users\maliadil\Desktop\{0}.xls'.format(5)
wb.SaveAs(r)

datetime Attribute error in python

I'm trying to run to following three lines of python code on command line using Python 3.5.0. It gives me an error- Attribute error: module 'datetime' has no attribute 'date'. I just want to print current date. Please help.
import datetime
current = datetime.date.today()
print(current)
There is nothing wrong with your code. It could be reduced a bit though:
import datetime
datetime.date
which should also cause the error. If this really causes the error, I would say your installation is messed up or, unlikely, there's a bug in Python. Please also make sure you don't have a datetime.py in your working directory. Further, check the output of dir(datetime) after importing it and with a different version of Python.
You shouldn't be getting any error running the above code as there is nothing wrong with it. Also rather than using the above code (which is okay syntax-wise but imports all the names accessible in the datetime moudule), you could use
from datetime import date
current = date.today()
print(current)
since all you want to import is the day's date.
when i run it on python 27. the code returns date with no errors!

Resources