Convert dictionary key to object name in Python

I've got a dictionary whose keys are country names, and its values are an object of the class Country, which has several attributes (population, area, etc.). For example: {"Chile":Country(17000000,124234,...)} However, when I try to reach a countr...
more »

2017-10-04 23:10 (0) Answers

On what data does sklearn Transformation operate?

I am writing a set of custom transformations in sklearn in order to clean the data in a pipeline. Each custom transformation takes two Pandas DataFrame as parameters for fit and transform, transform returns two DataFrames as well (see examples below)...
more »

2017-10-04 21:10 (1) Answers

Appium 1.7.1 with Crosswalk

I’ve noticed that crosswalk integration was added to appium back on may, but i’ve been having problems getting my test script to recognize the webview context once i added crosswalk to my project. I want to be able to write tests using the webvi...
more »

2017-10-04 18:10 (0) Answers

import numba on mac Sierra

I'm trying to install NUMBA on a mac machine (10.12.6). I've tried with CONDA: conda install numba I'm getting this: Fetching package metadata ........... Solving package specifications: . # All requested packages already installed. # packages...
more »

2017-10-04 18:10 (2) Answers

Formatting concatenated columns in Pandas/Python.

I am very new to Python/Pandas and am using the Spyder IDF, via the Anaconda distribution with Python 3.6 (maybe 3.7?).I am importing an Excel file via the code below and would like to know how to get an output that looks as follows: VOLTS/PHASE Cu...
more »

2017-10-04 17:10 (1) Answers

How to remove `duplicates' in list of instances

I have a list of instances of a certain class. This list contains `duplicates', in the sense that duplicates share the exact same attributes. I want to remove the duplicates from this list. I can check whether two instances share the same attributes...
more »

2017-10-04 16:10 (2) Answers

Random Numbers in a range around a median

I have a median and a standard deviation, what i want is to generate random numbers between the median-std and the median+std. I know how to do it like this: import numpy as np import random as rnd median=30 std=15 random_nr=rnd.randint(median-std...
more »

2017-10-04 15:10 (1) Answers

python , opencv, image array to binary

I have a large image , using cv2 module in python and some coordinates i cropped the image: img = cv.imread(image_path) crop_img = img[y1:y2,x1:x2] cv.imwrite(cropPath, crop_img) now the crop_img is a numpy.ndarray type. then I save this ima...
more »

2017-10-04 13:10 (2) Answers

How to merge/combine columns in pandas?

I have a (example-) dataframe with 4 columns: data = {'A': ['a', 'b', 'c', 'd', 'e', 'f'], 'B': [42, 52, np.nan, np.nan, np.nan, np.nan], 'C': [np.nan, np.nan, 31, 2, np.nan, np.nan], 'D': [np.nan, np.nan, np.nan, np.nan, 62, 70]} df =...
more »

2017-10-04 13:10 (2) Answers

Python Pandas Data frame creation

I tried to create a data frame df using the below code : import numpy as np import pandas as pd index = [0,1,2,3,4,5] s = pd.Series([1,2,3,4,5,6],index= index) t = pd.Series([2,4,6,8,10,12],index= index) df = pd.DataFrame(s,columns = ["MUL1"]) df["M...
more »

2017-10-04 12:10 (2) Answers

How to set the list by alphanumerical order?

I have a folder containing 10 subfolders with the following naming : Folder1,Folder2,Folder3,... i want to manipulate them by that order however when i apply lst = os.listdir(dirname) lst.sort() the output is the following : Folder1 Folder10 Fo...
more »

2017-10-04 10:10 (1) Answers

How do I cycle through images in Tkinter?

I want to have the button's image cycle through all possible pizza images, but instead it throws the following error when I click on it: self.config(image=next(self.images)) AttributeError: 'buttonInitialize' object has no attribute 'config' Here'...
more »

2017-10-04 04:10 (1) Answers

Vectorize numpy code

So I am trying to vectorize this code in numpy and im having trouble Heres is my for loop version which works as desired: B is a 3x3 Matrix for i in range(b.shape[0]): for j in range(b.shape[0]): Z[i,j] = np.sqrt(np.dot((b[i,:].T - b[...
more »

2017-10-04 02:10 (1) Answers

Python requests-cache multiple expirations

How do I set up different expiration timers for specific api requests I make with requests using the requests-cache library? Example, I want one specific call to be cached for a minute while another separate call url method is cached for an hour. ...
more »

2017-10-04 00:10 (0) Answers

Count words in a column of strings in Pandas

I have a pandas dataframe that contains queries and counts for a given time period and I'm hoping to turn this dataframe into a count of unique words. For example, if the dataframe contained the below: query count foo bar 10 super ...
more »

2017-10-03 22:10 (2) Answers

Flask to Numpy Image Conversion

I have been trying to send an image over javascript to a Flask server to draw bounding boxes on coordinates I received from my own API. How might I convert this to a numpy array? I was thinking of using the cv2.imdecode feature, but I don't want to ...
more »

2017-10-03 21:10 (1) Answers