Category "python-2.7"

"digitalocean" droplet password changing broke the website (502 Bad Gateway nginx/1.10.0 (Ubuntu))

I have changed the password of the digitalocean droplet then after that the website is not working at all and the api's for the mobile application is not workin

Python 3 f-string alternative in Python 2

Mostly I work with Python 3. There can I write this: print(f"The answer is {21 + 21}!") Output: The answer is 42! But in Python 2, f-strings do not exist. So

Python floating point is divisible by another floating point

Does anyone know a good way in Python to check if a number is divisible by another in floating point in python? The first thing I tried was ... 3.5 % 0.1 == 0.0

How to search for a 'text' or 'number' in a csv file with Python AND if exists print only first and second column values to a new csv file

I want to do the following using Python. Step-1: Read a specific third column on a csv file using Python. Step-2: Create a list with values got from step-1 Ste

ValueError: max_features must be in (0, n_features] in Random Forest

No code appears or error: ValueError: max_features must be in (0, n_features]. I have already tried the Stack solutions and I did not get a solution. Could anyo

Google foobar minion labor shifts challenge

I have a Google foobar challenge: Write a function called answer(data, n) that takes in a list of less than 100 integers and a number n, and returns that same

How to get the symmetric difference of two dictionaries

I was looking for a solution to finding the symmetric difference between two dictionaries in Python. For example, if I have two dictionaries A and B, and I wan

how to switch python interpreter in cmd?

I have installed both versions of python that is python 2.7 and python 3.5.3. When I run python command in command prompt, python 3.5.3 interpreter shows up. Ho

Python gives wrong result with .seconds attribute of timedelta data

>>>print(today - date, (today - date).seconds) [1] 63 days, 8:45:34.250649 31534 ↑ This is far away from the righ

Builtin python's __import__ vs imp.load_module: ValueError: Attempted relative import beyond toplevel package

I have a piece of code that dynamically imports a bunch of subpackages - package structure: main_package/ code_below_is_here.py game/ __init__.p

How to add a new array to an existing npz file in a standard way?

I have a function which writes an array to a compressed *.npz file: def save_a(file): np.savez_compressed(file, a=[[1, 2, 3]]) I want to make a function

403 "Request had insufficient authentication scopes" when creating drafts in Google API with Python

I am working with the google api for the first time, and am new to coding in general, and have a question that I'm sure is very simple, but I cannot find the an

How to check if a CSV has a header using Python?

I have a CSV file and I want to check if the first row has only strings in it (ie a header). I'm trying to avoid using any extras like pandas etc. I'm thinking

Create a ZipFile in memory and attach it to an email

I'm trying to modify an existing python script to convert an in-memory CSV into an (also in memory) zip archive and send it as an attachment to an email. I've h

Python: How to plot heat map of 2D matrix by ignoring zeros?

I have a matrix of size 500 X 28000, which contains a lot of zeros in between. But let us consider a working example with the matrix A: A = [[0, 0, 0, 1, 0],

Check if program runs in Debug mode

I use the PyCharm IDE for Python programming. Is there a possibility to check, whether I'm in debugging mode or not when I run my program? I use pyplot as plt a

ImportError: cadquery was unable to determine freecad library path

I am trying to run code from this source. The code is written in python 2, so I am using virtual environment with anaconda. The code replies on rather old versi

Python, Pandas ; ValueError('window must be an integer',)

I seem to be having this issue with Pandas code inside a Bokeh callback. Here's part of the output before the error. My dataframe seems normal and I'm not sure

How to compress folders using zipfile?

My program so far is successfully able to add and compress files which are present in the same directory as test.py but there is also a folder named location in

How can i fill in missing csv file value base on reference csv file

I have a reference file like this Id, Value1, Value2 a, a1, a2 b, b1, b2 c, c1, c2 d, d1, d2 ... n, n1, n2 and the missing file Id, Value1, Value2 d, ,