I am switched from Python 2.7 to Python 3.6. I have scripts that deal with some non-English content. I usually run scripts via Cron and also in Terminal. I had UnicodeDecodeError in my Python 2.7 scripts and I solved by this. Now in Python 3.6, it doesnt work. I have print statements like print(“Here %s” % (myvar)) and it throws
Tag: python-3.x
pivot_table requires more memory if dtype is category (MemoryError)
I have the following strange error with pandas(pandas==0.23.1) : I am wondering if this is expected and I am doing something wrong, or if this is a bug in pandas. Should dtype category for str not be very transparent (for this use case)? Answer This is not a bug. What’s happening is pandas.pivot_table is calculating the Cartesian product of grouper
Converting a YAML file to JSON object in Python
How can I load a YAML file and convert it to a Python JSON object? My YAML file looks like this: Answer you can use PyYAML And in the ipython console:
ModuleNotFoundError when running script from Terminal
I have the following folder structure: app __init__.py utils __init__.py transform.py products __init__.py fish.py In fish.py I’m importing transform as following: import utils.transform. When I’m running fish.py from Pycharm, it works perfectly fine. However when I am running fish.py from the Terminal, I am getting error ModuleNotFoundError: No module named ‘utils’. Command I use in Terminal: from app folder python
Extract coefficients and corresponding monomials from a given polynomial in SymPy
Given a symbolic multivariate polynomial P, I need to extract both its coefficients and corresponding monomials as lists: such that P is the dot product of coefficients and monomials, e.g., if P(x,y) = ax**2 + bxy + cy**2 then we should get coeffs = [a, b, c] and monoms = [x**2, x*y, y**2]. Getting the coefficients is easy since the
Calling super().__init__(**kwargs), and multiple inheritance?
I’m trying to learn and understand how to use super in Python, Ive been following the book ‘Python journey from novice to expert’ and although I feel that I understand the concept Im having problems executing super in my own code. For example, this method works for me: returns the following: This is what I expected (I’m not sure why
not seeing UDP multicast messages from another device
I have a Windows machine where I have two scripts that send and receive messages via UDP multicast (on the same machine). I have a C and Python3 implementation of this. The Python3 one looks like this: sender.py receiver.py I have another physical device hooked up to the same machine but I cannot receive any messages from it with my
AttributeError when reading a pickle file
I get the following error when I’m reading my .pkl files on spyder (python 3.6.5): The context: My program is made of one file: program.py In the program, a class Signal is defined as well as many functions. A simplified overview of the program is provided below: The function compute_data will return a list of tuples of the form: With,
Convert date object in normal format
When I am using a Python object, I get: This is not the format I need. We need to convert to this data format: How can I convert this in Python/Django? Example: It’s working fine, but how can I pass 2018-05-18 10:05:06 as database but database giving? It’s giving 2018-05-18 08:38:58+00:00. How can I check date as per 2018-05-18 08:38:58?
Set the format for pd.to_datetime
Hi already referred to this post but I could not get through my issue. I have a column in my CSV which is string and the sample values are below (note that the month and year positioning are sometimes reversed). What format do I need to set in my to_datetime? I tried all the below approaches I get the error