python

Apply rolling function on pandas dataframe with multiple arguments

假如想象 提交于 2021-02-19 16:35:53
问题 I am trying to apply a rolling function, with a 3 year window, on a pandas dataframe. import pandas as pd # Dummy data df = pd.DataFrame({'Product': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B'], 'Year': [2015, 2016, 2017, 2018, 2015, 2016, 2017, 2018], 'IB': [2, 5, 8, 10, 7, 5, 10, 14], 'OB': [5, 8, 10, 12, 5, 10, 14, 20], 'Delta': [2, 2, 1, 3, -1, 3, 2, 4]}) # The function to be applied def get_ln_rate(ib, ob, delta): n_years = len(ib) return sum(delta)*np.log(ob[-1]/ib[0]) / (n_years * (ob[-1]

Pycharm type checker - expected Series, got int

≡放荡痞女 提交于 2021-02-19 16:35:38
问题 I have very simple Python function that subtracts scalar value from pandas Series: def sub(x: pd.Series, a: int) -> pd.Series: return x - a It works as expected. I'm using type hints to enable type checker directly in my PyCharm IDE. The issue here is I get this warning message: Expected type 'Series', got 'int' instead As you can see in the image below: I understand that Python is dynamically typed language so in some cases type checking with type hints has its own limitations. But this

Python: Get caret position [closed]

拟墨画扇 提交于 2021-02-19 16:35:06
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 years ago . Improve this question I'm trying to get the caret position in Python. I tried using win32gui.GetCaretPos() but it always returns 0,0. Do you have any ideas how to make it work? Thanks Chris 回答1: If the caret is in a window created by another thread, you need to call AttachThreadInput.

Python Scrape With Normal Chrome or IE Browser (Not Chromedriver)

只谈情不闲聊 提交于 2021-02-19 16:33:39
问题 I'm using Selenium and Chromdriver which will load the site just fine including the Javascript loaded data. My problem is a normal Chrome browser will update over time when this data changes and the Chromedriver holds the first static data it was sent. I haven't had any better luck with PhantomJS or firefox as a webdriver. So is there anyway to use a normal Chrome browser? Or even IE? I know in theory I could have it load a Chrome browser and watch the network traffic for the data I'm looking

Python Scrape With Normal Chrome or IE Browser (Not Chromedriver)

给你一囗甜甜゛ 提交于 2021-02-19 16:31:11
问题 I'm using Selenium and Chromdriver which will load the site just fine including the Javascript loaded data. My problem is a normal Chrome browser will update over time when this data changes and the Chromedriver holds the first static data it was sent. I haven't had any better luck with PhantomJS or firefox as a webdriver. So is there anyway to use a normal Chrome browser? Or even IE? I know in theory I could have it load a Chrome browser and watch the network traffic for the data I'm looking

Python Scrape With Normal Chrome or IE Browser (Not Chromedriver)

做~自己de王妃 提交于 2021-02-19 16:30:34
问题 I'm using Selenium and Chromdriver which will load the site just fine including the Javascript loaded data. My problem is a normal Chrome browser will update over time when this data changes and the Chromedriver holds the first static data it was sent. I haven't had any better luck with PhantomJS or firefox as a webdriver. So is there anyway to use a normal Chrome browser? Or even IE? I know in theory I could have it load a Chrome browser and watch the network traffic for the data I'm looking

Illegal hardware instruction when trying to import tensorflow

廉价感情. 提交于 2021-02-19 15:41:25
问题 I just installed tensorflow using the instructions for the virtualenv method. The installation process went smoothly, so I don't think there was any problem there. After installation I proceeded to try and import it to validate that everything is ok, and I got the following message: [1] 4492 illegal hardware instruction (core dumped) python This happened after I use the following command using th python interactive console: import tensorflow as tf I tried using the link with pip to reinstall

Illegal hardware instruction when trying to import tensorflow

扶醉桌前 提交于 2021-02-19 15:41:24
问题 I just installed tensorflow using the instructions for the virtualenv method. The installation process went smoothly, so I don't think there was any problem there. After installation I proceeded to try and import it to validate that everything is ok, and I got the following message: [1] 4492 illegal hardware instruction (core dumped) python This happened after I use the following command using th python interactive console: import tensorflow as tf I tried using the link with pip to reinstall

Illegal hardware instruction when trying to import tensorflow

谁说胖子不能爱 提交于 2021-02-19 15:40:33
问题 I just installed tensorflow using the instructions for the virtualenv method. The installation process went smoothly, so I don't think there was any problem there. After installation I proceeded to try and import it to validate that everything is ok, and I got the following message: [1] 4492 illegal hardware instruction (core dumped) python This happened after I use the following command using th python interactive console: import tensorflow as tf I tried using the link with pip to reinstall

Secondary / Parallel X-Axis on Plotly charts (python)

天涯浪子 提交于 2021-02-19 15:10:40
问题 I need to render at_risk numbers on a Kaplan Meier graph. The end result should be similar to this: The bit I am having trouble rendering is the No. of patients at risk at the bottom of the graph. The values displayed there, correspond to the values on the x-axis. So in essence, it's like a Y-axis rendered in parallel with the X. I have been trying to replicate multiple-axis found here (https://plot.ly/python/multiple-axes/) without success, and also tried having a subplot and hide everything