python-2.7

GroupBy with sub-ranges in Pandas

女生的网名这么多〃 提交于 2021-01-28 06:53:07
问题 I am researching soccer dataset LEAGUE HOME DRAW AWAY WINNER PREDICTED PROFIT 0 2 3.25 3.25 2.10 0 2 -10.0 1 14 1.50 3.50 6.00 0 0 5.0 2 2 2.25 3.30 3.20 2 0 -10.0 3 11 2.25 3.00 2.88 0 0 12.5 4 17 5.00 3.75 1.70 2 2 7.0 Now, I am looking for approach GroupBy(League, 1.25 < Home < 1.5 | 1.5 < Home < 1.75 ..) and get target dataset as on example: LEAGUE HOME PROFIT 0 2 1.25-1.5 10.0 1 2 1.50-1.75 5.0 2 3 NaN NaN 3 3 1.5-1.75 12.5 ... 回答1: Maybe you need cut: bins = np.linspace(0, 5, 20,

Cartesian Product memory error converting itertools.product to list

怎甘沉沦 提交于 2021-01-28 06:50:34
问题 I'm trying to create the Cartesian product of a list of lists. When I try to convert the result to a list it will give me a memory error. If I run it without converting it to a list it runs fine. lists = [['a','b','c' ],['a','b','c' ],['a','b','c' ],['a','b','c' ],['a','b','c' ],['a','b','c' ],['a','b','c' ],['a','b','c' ],['a','b','c' ]] my_product = list(itertools.product(*lists)) I even tried to filter through some of the result using itertools.dropwhile to make it smaller before

On Plone 4.3.15, how to install latest Stripe's API

不问归期 提交于 2021-01-28 06:50:22
问题 On Plone 4.3.15 (Universal installation), it is not possible to install stripe 2.32.1. See logs : Getting distribution for 'stripe==2.32.1'. /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'project_urls' warnings.warn(msg) /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'long_description_content_type' warnings.warn(msg)

How to implement .dat file for handwritten recognition using SVM in Python

萝らか妹 提交于 2021-01-28 06:35:27
问题 I've been trying to train Hand-written Digits using SVM based on the code on OpenCV library. My training part is as follow: import cv2 import numpy as np SZ=20 bin_n = 16 svm_params = dict( kernel_type = cv2.SVM_LINEAR, svm_type = cv2.SVM_C_SVC, C=2.67, gamma=5.383 ) affine_flags = cv2.WARP_INVERSE_MAP|cv2.INTER_LINEAR def deskew(img): m = cv2.moments(img) if abs(m['mu02']) < 1e-2: return img.copy() skew = m['mu11']/m['mu02'] M = np.float32([[1, skew, -0.5*SZ*skew], [0, 1, 0]]) img = cv2

How to swap columns using openpyxl

天大地大妈咪最大 提交于 2021-01-28 06:27:55
问题 I've .xlsx file. Rows are good, values are just fine. But i need to change the columns order by list of new columns positions, e.g: old = [1, 2, 3, 4] new = [2, 1, 4, 3] Docs are checked - there is no straightforward options for this problem. I've tried to iterate over columns, so: old = {cell.column: cell.value for cell in ws[1]}.keys() # [1, 2, 3, 4] new = [2, 1, 4, 3] for i, col in enumerate(ws.iter_cols(max_col=old[-1]), 1): if old[i-1] != new[i-1]: for one in ws[get_column_letter(i)]:

Python Selenium Set Multiple Chrome Preference

荒凉一梦 提交于 2021-01-28 06:25:25
问题 I am trying to set multiple chrome options in my chrome browser. This is what I currently have: prefs = {"download.default_directory" : "Download/Path"} moreprefs = {'safebrowsing.enabled': 'false'} chromeOptions = webdriver.ChromeOptions() chromeOptions.add_experimental_option("prefs", prefs) chromeOptions.add_experimental_option("prefs", moreprefs) self.driver = webdriver.Chrome(chrome_options=chromeOptions) The probblem is it only takes in to account the 1 of the chromeOptions.add

Script for working out exponential limit within a set range

牧云@^-^@ 提交于 2021-01-28 06:23:51
问题 In the image above column B is multiples of A1 and column C is C = C + B (working down the rows) I worked out that in order for C for be 50 in 20 rows A1 has to be 0.2631579 but I'd like to be able to simplify that to a function that will return a list: list = exp(50, 20). I'm not sure about the terminology of such a script so researching beforehand didn't really bring anything up sorry. 回答1: Well based on your problem statement, we know that: B n =(n-1)×a ; and C n =(n-1)×n×a/2 (here a is

Python: Scroll a ScrolledText automatically to the end if the user is not scrolling manually

孤者浪人 提交于 2021-01-28 06:20:45
问题 I made my ScrolledText scroll automatically to the end, based on this answer. Now I'd like to scroll automatically only if the user is not scrolling manually . I was looking for something like this: self.text.offsetBottom (see my comment in the code below) , but couldn't find it yet. Any ideas? Thanks! import time from Tkinter import * import ScrolledText class Example(Frame): def __init__(self, *args, **kwargs): Frame.__init__(self, *args, **kwargs) self.text = ScrolledText.ScrolledText(self

matplotlib.pyplot.axes() arguments confusion

一曲冷凌霜 提交于 2021-01-28 06:07:17
问题 The objective is to insert a sub_figure in a simple plot as follows: import numpy as np from matplotlib import pyplot as plt X = np.linspace(-6, 6, 1024) Y = np.sinc(X) X_detail = np.linspace(-3, 3, 1024) Y_detail = np.sinc(X_detail) plt.plot(X, Y, c = 'k') sub_axes = plt.axes([0.6,0.6,0.25,0.25]) sub_axes.plot(X_detail, Y_detail, c = 'k') plt.setp(sub_axes) plt.show() The code above gives the following output: The matplotlib documentation says the argument the matplotlib.pyplot.axes()

Python 2.7.2 doesn't properly iterate through logger's handlers

烈酒焚心 提交于 2021-01-28 06:04:17
问题 the following code is very simple, but for some reason, for-loop does not iterate through all handlers of the logger. however, for-loop does iterate through all handlers if we remove my_logger.removeHandler( handler ) in the else clause. any idea if I'm doing anything wrong? import logging import sys stdf = logging.Formatter( "%(message)s" ) filef = logging.Formatter( "%(message)s" ) my_logger = logging.getLogger( "file std logger" ) stdh = logging.StreamHandler( sys.stdout ) stdh