Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
unpacked robinhood
Feb 18, 2013

by Fluffdaddy
Thanks. I've got one last question for today.
I use Flask to expose a web interface and run methods on my backend thing.
At the moment flask instantiates the backend, and answers requests from the interface by calling backend methods and returning the result. I'm not sure it's good design but it seems to works ok.

Can the backend run http requests on the flask instance too, as a way to send status updates to be consumed from the web side ?

At the moment I'd like to show a progress bar while a request is processed, which can take up to a few minutes. (I've never done web stuff and it shows :ohdear: )

Adbot
ADBOT LOVES YOU

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Insert-web-framework-here is just a function. All the views and decorators and middleware and templates...all of it boils down to The Function.

From the standpoint of you, the developer, there is no server. Nothing running in a loop waiting to handle web requests. There is just The Function.

You can do whatever you want in The Function. The only things required of this function is that it takes in the data from the request (in python the format of this data is a standard for frameworks called WSGI) and that it returns a string that can be interpreted by clients as a valid response.

By itself, Flask or Django or whatever can only handle one request/response at a time. However, in production and in development, the server you are running is not a Flask or Django server. It is another multithreaded or async server that can handle multiple requests and responses at a time, and that is what allows you to make calls "to yourself" from within The Function. If you make a request from inside The Function to http://127.0.0.1:8000/some/path/here/, your web server (nginx or runserver or run or gunicorn or blah blah blah) will call The Function again and now The Function is running in two different threads. One thread is waiting on the second thread to give a response.

All that being said, what is usually done is that you just do whatever from right inside your view rather than calling another url. For example, if you have an endpoint for POSTing new Foobars which creates a row in a database table and as part of another endpoint Foobars get created, it's lower overhead to just do the database calls from inside that second view rather than POSTing to your dedicated view for creating Foobars.

CarForumPoster
Jun 26, 2013

⚡POWER⚡

Sad Panda posted:

Very. I'll be logging in to each site and there's not going to be much standardisation.

There are updates every now and then but infrequently enough that once I get it all done at first I don't mind tweaking it when they change.

I do exactly this with a different, easier, non-python solution. For what industry and purpose are you doing this project?

Hed
Mar 31, 2004

Fun Shoe

Thermopyle posted:

Kenneth Reitz did a talk on Pipenv that might be useful for anyone wondering why they should use Pipenv.

https://www.youtube.com/watch?v=GBQAKldqgZs

Thanks, this was neat and I'll give it a shot.

Sad Panda
Sep 22, 2004

I'm a Sad Panda.

CarForumPoster posted:

I do exactly this with a different, easier, non-python solution. For what industry and purpose are you doing this project?

It's personal use, no form of industry. I'm logging into betting websites. What's the easier option? I considered a Pyautogui setup which is just recording a series of clicks and using OCR + Image Recognition, but Selenium seemed like an interesting way to start.

I managed to get the login working on 145/155 websites. The other ones are throwing up Selenium errors. A few of them because elements are tagged as invisble so Selenium doesn't want to interact with them.

Python code:

def login_main(site_details):
    """ Sets variables, loads browser"""
    driver = load_browser()

    # Reads the details.
    URL = site_details[0][1]
    TITLE = site_details[0][0]
    USERNAME = site_details[0][3]
    PASSWORD = str(site_details[0][4])[2:-1]
    USERNAME_ID = site_details[0][5]
    TO_CLICK = site_details[0][6]
    IFRAME_ID = site_details[0][7]

    load_page(driver, URL, TITLE)
    if TO_CLICK:
        click_first(driver, TO_CLICK)

    # Can't use just existence, because this is sometimes 0 which it classes as false.
    if IFRAME_ID == "0" or IFRAME_ID == "1" or IFRAME_ID == "2" or IFRAME_ID == "3":
	    switch_iframe(driver, IFRAME_ID)
    debug.sleep(3, "cos")
    login(driver, USERNAME, PASSWORD, USERNAME_ID)


def load_browser():
    """ Window size set to stop mobile sites being loaded."""
    # This ChromeOptions is to make it so it does not shut at the end which is useful for debugging.
    opts = webdriver.ChromeOptions()
    opts.add_experimental_option("detach",True)
    driver = webdriver.Chrome(chrome_options=opts)

    driver.set_window_position(0, 0)
    driver.set_window_size(1400, 768)
    return driver


def load_page(driver, url, title):
    """ Loads URL and throws an AssertionError if it's not the page expected based on title. """
    driver.get(url)
#    debug.sleep(10, "cos")
    print(driver.title)
    assert title in driver.title, f"Not {url}"
    print(f"On {url}")
    logging.info(f"On {url}")


def click_first(driver, click_button_id):
    # For logins that need to click a button to reveal the login boxes.
    try:
        print("Need to click first.")
        logging.info("Attempting login.")

        wait_for_presence(driver, By.CSS_SELECTOR, click_button_id)

        to_click_id = driver.find_element_by_css_selector(click_button_id)
        to_click_id.click()

    except Exception as e:
        name = inspect.stack()[0][3]
        error_message(e, driver, name)
    print("Clicked.")
    logging.info("Clicked.")

def switch_iframe(driver, number):
    print(f"Switching to iframe {number}")
    iframe = driver.find_elements_by_tag_name('iframe')[number]
    driver.switch_to_frame(iframe)

def login(driver, username, password, username_id):
    # Inputs the username, tabs to the password, enters it and logs in.
    try:
        print("Attempting login.")
        logging.info("Attempting login.")

        # Waiting for presence ensures the page loads.
        wait_for_presence(driver, By.CSS_SELECTOR, username_id)
        username_elem = driver.find_element_by_css_selector(username_id)


        debug.highlight(username_elem)

        username_elem.click()
        debug.sleep(1, "testing.")
        username_elem.send_keys(username)
        username_elem.send_keys(Keys.TAB)
        element = driver.switch_to.active_element
        element.clear()
        element.send_keys(password)
        debug.sleep(1, "testing.")
        element.send_keys(Keys.ENTER)
    except Exception as e:
        name = inspect.stack()[0][3]
        error_message(e, driver, name)
    print("Logged in.")
    logging.info("Logged in.")

CarForumPoster
Jun 26, 2013

⚡POWER⚡

Sad Panda posted:

It's personal use, no form of industry. I'm logging into betting websites. What's the easier option? I considered a Pyautogui setup which is just recording a series of clicks and using OCR + Image Recognition, but Selenium seemed like an interesting way to start.

I managed to get the login working on 145/155 websites. The other ones are throwing up Selenium errors. A few of them because elements are tagged as invisble so Selenium doesn't want to interact with them.


Some learning curve to this, decent documentation, and $150/month but many good features. It was much mroe robust and allowed faster deployment than trying anything with BeautifulSoup and the like.
https://www.parsehub.com/

EDIT: Its free to use with a limited feature set and what not but I ended up needing several of their not free features. E.G. I dont want my projects to become public.

CarForumPoster fucked around with this message at 18:36 on May 20, 2018

unpacked robinhood
Feb 18, 2013

by Fluffdaddy

Thanks for the write up Thermopyle.

Sad Panda
Sep 22, 2004

I'm a Sad Panda.
Anyone experienced with Selenium? I'm trying to perform a hover, but it doesn't seem to work.

https://www.galabingo.com/
That's the site in question. The login button does not seem to want to be clicked on, and the username + password boxes only appear when that is hovered over. Maybe this can be achieved by Javascript but I'm lost on that too.


Python code:
from selenium import webdriver
from selenium.webdriver import ActionChains
import time

driver = webdriver.Chrome()
driver.get('http://www.galabingo.com')

time.sleep(5)
element = driver.find_element_by_css_selector('[class="hidden-btn  fn-login-overlay"]')

hover = ActionChains(driver).move_to_element(element)

hover.perform()

breaks
May 12, 2001

I didn't try it because I don't have Selenium up to date at home, but from looking at the page you probably want to hover the div.fn-show-login-tooltip element instead.

Sad Panda
Sep 22, 2004

I'm a Sad Panda.

breaks posted:

I didn't try it because I don't have Selenium up to date at home, but from looking at the page you probably want to hover the div.fn-show-login-tooltip element instead.

Thanks! That worked perfectly.

As someone said to me.. "Selenium is probably not too bad if using it for what its intended use is... (automated testing of websites you are devving), but for automating sites we dont own it does become trickier to use."

149/155 sites isn't bad.

2 with invisible elements that I can't interact with. 2 more with 'cannot focus element' and 2 more that don't like being opened in Chrome (throws a CAPTCHA) but Firefox works just fine and spoofing the User-Agent doesn't work so I'm not sure what it's using to detect that.

Boris Galerkin
Dec 17, 2011

I don't understand why I can't harass people online. Seriously, somebody please explain why I shouldn't be allowed to stalk others on social media!

Linear Zoetrope posted:

In numpy (or some interoperable library like pandas) is there a way to create basic shapes like triangles or circles in an ndarray/tensor/table/whatever? I'm featurizing a space of entities represented like {pos = (x,y) , shape = Triangle{base_len = 1.5}, ...} or whatever and while I'm entirely capable of writing this myself* it would be nice to be able to just have python do it.

Specifically I have C channels, each of which represent a different aspect, such as hitpoints or a one-hot encoding of things like faction or unit type (domain is a custom RTS), and I'm trying to fill all of these channels based on the current state of the gameboard, but they have different primitive shapes and approximating them all as rectangles would overfill too much. I'm essentially looking to "rasterize" the (continuous-valued) game state, but with data other than colors, and then feed it into a NN. (I'm researching a way to represent this data as different sorts of NN inputs, but I need this crude representation for the time being as a baseline).

Unfortunately searching for anything relating to words like "triangle" or "shape" and "numpy" yield results about the shape property or triangular matrices so it's hard to find relevant info.

* In fact, I did write this myself in the engine in another language, but it's plagued with issues trying to intuit the "true" shape of the tensor from the python side, and I'm trying to move this to only sending over entity data as described and featurize it into an ndarray on the python side.

I'm not really sure I understand what you're asking. My first thought for a grid of triangles is you're looking for a mesh but I also have no idea what "C channels" or "feed it into a NN" means so :shrug:.

unpacked robinhood
Feb 18, 2013

by Fluffdaddy

Boris Galerkin posted:

"feed it into a NN"

Neural network maybe ?

Nippashish
Nov 2, 2005

Let me see you dance!

Linear Zoetrope posted:

In numpy (or some interoperable library like pandas) is there a way to create basic shapes like triangles or circles in an ndarray/tensor/table/whatever? I'm featurizing a space of entities represented like {pos = (x,y) , shape = Triangle{base_len = 1.5}, ...} or whatever and while I'm entirely capable of writing this myself* it would be nice to be able to just have python do it.

Numpy isn't an image library so it doesn't have functions like this. Your best bet I think is to use Pillow to draw a greyscale image for each channel and then convert those to numpy arrays and stack them. Pillow has a polygon function that should suit your needs, and you can convert a Pillow image to a numpy array with np.asarray(my_image).

Linear Zoetrope
Nov 28, 2011

A hero must cook
Thanks, I actually just found skimage.draw which provides almost exactly what I need. It's nice because it generates indices so I can do things like

code:
rr,cc = polygon(...)

features[rr,cc,0] = obj.hitpoints / max_hp
features[rr,cc,1] = 1 if obj.faction == 0 else 0
features[rr,cc,2] = 1 if obj.faction == 1 else 0
And yes, NN is neural net.

Feral Integral
Jun 6, 2006

YOSPOS

Sad Panda posted:

Anyone experienced with Selenium?

It's been a while since I've used this stuff for work, but if you want to save some hassle, check out https://splinter.readthedocs.io/en/latest/ . It's a bit simpler and the documentation is good. Makes for cleaner looking source, too.

Sad Panda
Sep 22, 2004

I'm a Sad Panda.
I've got an array of 3 strings, that are only different by a single character (the child number).

Python code:
memorable_elements_css = ['div.control.control--complex.passnumber-partial-entry.control--enabled.control--loaded > div.control__input > div:nth-child(1) > label > span', ...]
I'll be accessig them through a for loop. Is there anyway to just use a single string? The only idea that comes to mind would be something along the lines of...

Python code:
for i in range (1, 4):
     the_function_i_want_to_use(memorable_element_string)
     memorable_element_string = memorable_element_string.replace(str(i), str(i+1))
Bad idea? Just store 3 long strings in my list?

Feral Integral posted:

It's been a while since I've used this stuff for work, but if you want to save some hassle, check out https://splinter.readthedocs.io/en/latest/ . It's a bit simpler and the documentation is good. Makes for cleaner looking source, too.

Thanks for the suggestion. Selenium seems to be going OK at the moment. Does Splinter click on elements that are not visible? That's one of the things that frustrates me with Selenium. I've got to insert some Javascript, to aria-hidden to false, or some other things.

Sad Panda fucked around with this message at 00:22 on May 24, 2018

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

I haven't tried it, but on the next project where I need Selenium, I'm going to look into using pyppeteer instead.



Sad Panda posted:

I've got an array of 3 strings, that are only different by a single character (the child number).

Python code:
memorable_elements_css = ['div.control.control--complex.passnumber-partial-entry.control--enabled.control--loaded > div.control__input > div:nth-child(1) > label > span', ...]
I'll be accessig them through a for loop. Is there anyway to just use a single string? The only idea that comes to mind would be something along the lines of...

Using f-strings in py3.6.

Or you can use a format string in lower python versions.

Python code:
for i in range(blah):
	stringythingy = f'div.control.control--complex.passnumber-partial-entry.control--enabled.control--loaded > div.control__input > div:nth-child({i}) > label > span'
	boopityboop(stringythingy)

necrotic
Aug 2, 2005
I owe my brother big time for this!
Just do f"shared.string.{i}"

edit almost

Mad Jaqk
Jun 2, 2013
On the off chance you'd rather have the string declared elsewhere in your code rather than in the for-loop, or are using an older version of Python, you can also do this:

Python code:
s = "I'm string {}"
for i in range(3):
    print(s.format(i))

breaks
May 12, 2001

Sad Panda posted:

Thanks for the suggestion. Selenium seems to be going OK at the moment. Does Splinter click on elements that are not visible? That's one of the things that frustrates me with Selenium. I've got to insert some Javascript, to aria-hidden to false, or some other things.

Selenium/Webdriver's purpose is to emulate interacting with the browser as a user would, so you shouldn't need to click an element that isn't visible, because the user would actually be interacting with some other element instead of the hidden one.

YMMV for sites that are trying to deliberately break browser automation or otherwise doing something insane, but most of the time in this situation, you've either got the wrong element, or you've got the right element but aren't waiting for it to get into an interactable state.

If you want to provide some more information about the error, site, or whatever else is relevant, I'll be glad to have a look and see if anything pops out. A fair part of my job is dealing with this poo poo.

breaks fucked around with this message at 07:20 on May 24, 2018

Sad Panda
Sep 22, 2004

I'm a Sad Panda.
Of course. f-strings. Thanks for that! I love those things dearly so can't think why I didn't consider them. I'll say it's cos it was past midnight...

breaks posted:

Selenium/Webdriver's purpose is to emulate interacting with the browser as a user would, so you shouldn't need to click an element that isn't visible, because the user would actually be interacting with some other element instead of the hidden one.

YMMV for sites that are trying to deliberately break browser automation or otherwise doing something insane, but most of the time in this situation, you've either got the wrong element, or you've got the right element but aren't waiting for it to get into an interactable state.

If you want to provide some more information about the error, site, or whatever else is relevant, I'll be glad to have a look and see if anything pops out. A fair part of my job is dealing with this poo poo.

I think it's people trying to deliberately break browser automation. My current project is basically writing something to work out how much money I have across all my accounts. Those accounts include bank accounts, but also a bunch of betting websites (I'm in the UK where it's nice and legal).

Three examples of sites that refuse to work (claiming not visible/cannot focus) without some form of skullduggery include

1) https://spinson.com

Here I can click on the login button as needed, but then if I try to interact with the username form it throws an error. The following gets around it through. I've no idea why using that Javascript, which uncovers a 3rd input box on the login field works, but it does.

Python code:
to_click_id = '[id="mainLoginBtn"]'
username_id = '#login-pane > div.username_wrap > div > div > div > input:nth-child(1)'

driver = webdriver.Chrome()
driver.get(URL)
time.sleep(2)

to_click = driver.find_element_by_css_selector(to_click_id)
to_click.click()

time.sleep(2)
iframe = driver.find_elements_by_tag_name('iframe')[0]
driver.switch_to_frame(iframe)

driver.execute_script("document.getElementsByName('username')[0].setAttribute('style', 'display: inline-block');")
username_elem = driver.find_element_by_css_selector(username_id)
username_elem.send_keys(username)
username_elem.send_keys(Keys.TAB)
element = driver.switch_to.active_element
element.send_keys(Keys.TAB)
element = driver.switch_to.active_element
element.send_keys(password)
element.send_keys(Keys.ENTER)
2) https://www.kingjackcasino.com

The same issue. I can click on login, but then can't interact with the username field. I've tried
HTML code:
[class="login-box__input-wrapper"]
and the Chrome generated selector which is...
HTML code:
#ui-login-form > div:nth-child(1) > input[type="text"]
They both throw 'not visible'.

3) Nationwide Online Banking. (https://onlinebanking.nationwide.co.uk/AccessManagement/Login). If you type in a random 10 digit customer number, click on Log in using memorable data, type a random thing into memorable data then the passnumber dropdowns become interactable. However, the dropdown values are hidden with aria-hidden = true
JavaScript code:
"document.getElementsByClassName('selection-list__value')[0].setAttribute('aria-hidden', 'false');"
That allows me to interact with them using Selenium.

Sad Panda fucked around with this message at 10:36 on May 24, 2018

SurgicalOntologist
Jun 17, 2004

YMMV but I've always found it easier to reverse engineer the backend API by checking out the AJAX calls in Chrome Developer Tools. Extra bonus is that you sometimes uncover extra internal data that they don't bother to expose in the front-end.

bamhand
Apr 15, 2010
I'm having trouble getting matplotlib to overlay two plots on top of each other instead of creating two different plots and I'm not sure what I'm doing wrong in my example when I'm googling the issue:
code:
        a.plot(
                        x="date",
                        y="heloc2",
                        title='In-sample Fit Chart', 
                        linewidth=1,
                        linestyle='-', 
                        marker='d',
                        markersize=5,
                        fillstyle='none',
                        color='cornflowerblue', 
                        label='Original Dependent Values')
        a.plot(
                        x="date",
                        y="pred",
                        kind='line',
                        linewidth=1,
                        marker='o',
                        markersize=5,
                        fillstyle='none',
                        linestyle='-', 
                        color='red', 
                        label='Predicted Dependent Values')

        plt.xlabel('Date')
        plt.ylabel(self.var_dic[self.est_data_obj.endog], size=10)
        plt.legend() 
        plt.show()

bamhand fucked around with this message at 16:54 on May 24, 2018

vikingstrike
Sep 23, 2007

whats happening, captain
Is "a" an Axes object?

bamhand
Apr 15, 2010
I think it's a dataframe? I'm modifying some old code where I'm just changing the source of the data but trying to keep the plots the same. This is what was working before (also I'm pretty new to python in general):
code:
a1 = self.est_data_obj.tsa_data[self.est_data_obj.endog][self.est_data_obj.bgn_obs : self.est_data_obj.end_obs]
        a2 = self.reg_results.fittedvalues[self.est_data_obj.bgn_obs : self.est_data_obj.end_obs]
        a1.plot(
                        title='In-sample Fit Chart', 
                        linewidth=1,
                        linestyle='-', 
                        marker='d',
                        markersize=5,
                        fillstyle='none',
                        color='cornflowerblue', 
                        label='Original Dependent Values')

        a2.plot(
                        kind='line',
                        linewidth=1,
                        marker='o',
                        markersize=5,
                        fillstyle='none',
                        linestyle='-', 
                        color='red', 
                        label='Predicted Dependent Values')
                        
        plt.xlabel('Date')
        plt.ylabel(self.var_dic[self.est_data_obj.endog], size=10)
        plt.legend() 
        plt.show()
This is the new code I added for changing the data, where sd2df creates a dataframe from saspy:

a = self.sas.sd2df("reg_out", "work").loc[:,["date","heloc2","pred"]]
a=a.loc[a["heloc2"].notnull(),]

bamhand fucked around with this message at 16:54 on May 24, 2018

Proteus Jones
Feb 28, 2013



bamhand posted:

I think it's a dataframe? I'm modifying some old code where I'm just changing the source of the data but trying to keep the plots the same. This is what was working before (also I'm pretty new to python in general):

a1 = self.est_data_obj.tsa_data[self.est_data_obj.endog][self.est_data_obj.bgn_obs : self.est_data_obj.end_obs]
a2 = self.reg_results.fittedvalues[self.est_data_obj.bgn_obs : self.est_data_obj.end_obs]
a1.plot(
title='In-sample Fit Chart',
linewidth=1,
linestyle='-',
marker='d',
markersize=5,
fillstyle='none',
color='cornflowerblue',
label='Original Dependent Values')

a2.plot(
kind='line',
linewidth=1,
marker='o',
markersize=5,
fillstyle='none',
linestyle='-',
color='red',
label='Predicted Dependent Values')

plt.xlabel('Date')
plt.ylabel(self.var_dic[self.est_data_obj.endog], size=10)
plt.legend()
plt.show()


This is the new code I added for changing the data, where sd2df creates a dataframe from saspy:

a = self.sas.sd2df("reg_out", "work").loc[:,["date","heloc2","pred"]]
a=a.loc[a["heloc2"].notnull(),]

Use the code tags. It makes it infinitely easier to read your code.

code:

	a1 = self.est_data_obj.tsa_data[self.est_data_obj.endog][self.est_data_obj.bgn_obs : self.est_data_obj.end_obs]
        a2 = self.reg_results.fittedvalues[self.est_data_obj.bgn_obs : self.est_data_obj.end_obs]
        a1.plot(
                        title='In-sample Fit Chart', 
                        linewidth=1,
                        linestyle='-', 
                        marker='d',
                        markersize=5,
                        fillstyle='none',
                        color='cornflowerblue', 
                        label='Original Dependent Values')

        a2.plot(
                        kind='line',
                        linewidth=1,
                        marker='o',
                        markersize=5,
                        fillstyle='none',
                        linestyle='-', 
                        color='red', 
                        label='Predicted Dependent Values')
                        
        plt.xlabel('Date')
        plt.ylabel(self.var_dic[self.est_data_obj.endog], size=10)
        plt.legend() 
        plt.show()

Cingulate
Oct 23, 2012

by Fluffdaddy

bamhand posted:

I think it's a dataframe? I'm modifying some old code where I'm just changing the source of the data but trying to keep the plots the same. This is what was working before (also I'm pretty new to python in general):
code:
a1 = self.est_data_obj.tsa_data[self.est_data_obj.endog][self.est_data_obj.bgn_obs : self.est_data_obj.end_obs]
        a2 = self.reg_results.fittedvalues[self.est_data_obj.bgn_obs : self.est_data_obj.end_obs]
        a1.plot(
                        title='In-sample Fit Chart', 
                        linewidth=1,
                        linestyle='-', 
                        marker='d',
                        markersize=5,
                        fillstyle='none',
                        color='cornflowerblue', 
                        label='Original Dependent Values')

        a2.plot(
                        kind='line',
                        linewidth=1,
                        marker='o',
                        markersize=5,
                        fillstyle='none',
                        linestyle='-', 
                        color='red', 
                        label='Predicted Dependent Values')
                        
        plt.xlabel('Date')
        plt.ylabel(self.var_dic[self.est_data_obj.endog], size=10)
        plt.legend() 
        plt.show()
This is the new code I added for changing the data, where sd2df creates a dataframe from saspy:

a = self.sas.sd2df("reg_out", "work").loc[:,["date","heloc2","pred"]]
a=a.loc[a["heloc2"].notnull(),]
pd.DataFrame's plot method takes an ax argument. I.e., do

axes = pt.axes()
df_1.plot(..., ax=ax)
df_2.plot(..., ax=ax)

and both calls will show up in the same axes.

Better: use seaborn instead.
If you want to plot predicted vs. actual, consider using seaborn.jointplot.

bamhand
Apr 15, 2010
Awesome, thank you.

vikingstrike
Sep 23, 2007

whats happening, captain

Cingulate posted:

pd.DataFrame's plot method takes an ax argument. I.e., do

axes = pt.axes()
df_1.plot(..., ax=ax)
df_2.plot(..., ax=ax)

and both calls will show up in the same axes.

Better: use seaborn instead.
If you want to plot predicted vs. actual, consider using seaborn.jointplot.

Yep. If they are DataFrames this is the right fix. I generally do f, ax = plt.subplots(1, 1), so I go ahead and get the figure object too, since I make a couple of tweaks and normally save to file instead of an interactive view.

bamhand
Apr 15, 2010
New question, if I'm working in Jupyter Notebook and I make a change to one of my imported files, what do I need to do to get the notebook to acknowledge that?

Example:
I have some program prog.py and I import prog2.py into it. In Spyder I can update prog2.py, hit, save, and then when I run prog.py it uses the new version. This doesn't appear to be the case in Jupyter Notebook.

SurgicalOntologist
Jun 17, 2004

There are ways to reload, but the easiest is just to restart the kernel. Kernel > Restart / Restart and run all.

Boris Galerkin
Dec 17, 2011

I don't understand why I can't harass people online. Seriously, somebody please explain why I shouldn't be allowed to stalk others on social media!

SurgicalOntologist posted:

There are ways to reload, but the easiest is just to restart the kernel. Kernel > Restart / Restart and run all.

00 (two zeros) is the default shortcut to do that.

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.
Is there a way to restart the kernel and re-run everything up to this point?

Boris Galerkin
Dec 17, 2011

I don't understand why I can't harass people online. Seriously, somebody please explain why I shouldn't be allowed to stalk others on social media!

KernelSlanders posted:

Is there a way to restart the kernel and re-run everything up to this point?

Do you mean like rerun all cells up to the current one selected (vs rerunning all cells period)? I’d like to know that too. What I do now is just insert a cell underneath where I’d like to stop and just type asdf so it fails and execution stops :v:

Cingulate
Oct 23, 2012

by Fluffdaddy

Boris Galerkin posted:

Do you mean like rerun all cells up to the current one selected (vs rerunning all cells period)? I’d like to know that too. What I do now is just insert a cell underneath where I’d like to stop and just type asdf so it fails and execution stops :v:
I write "error" instead of asdf, which somehow feels more fitting.

vikingstrike
Sep 23, 2007

whats happening, captain
Isn’t that an option in one of the drop down menus of the notebook? I believe it’s in the menu that you restart kernel. It was added in a recent-ish update I believe.

cinci zoo sniper
Mar 15, 2013




I vaguely remember something about cells having “run above” option, but I’m not a frequent Jupyter user.

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.
Yeah, in the notebook there's a "run above." That doesn't help in the console though.

SurgicalOntologist
Jun 17, 2004

I didn't realize you meant in the console... that's a fantastic idea, if it existed I would use it all the time. That's worth writing a %magic command for or at least a feature proposal to the developers.

Adbot
ADBOT LOVES YOU

vikingstrike
Sep 23, 2007

whats happening, captain
Oh oops. Missed the console bit.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply