Ansible, pip and virtualenv
Hi I wrote an Ansible .yml to deploy a Flask webapp. I use python 3.6 for the ansible-playbook executable. The yml starts with some yum installs, amongst which python-pip. That installs an ancient pip version (v9). Then I create a virtualenv where I use a requirements.txt for pip install -r. Should I precede that step with a separate --upgrade pip step? Or should pip just be in my requirements.txt? Separate question: what locations do I need to specify in my pip --trusted-host list? Could it be that this has recently changed? I suddenly got SSL errors. Thanks in advance! Albert-Jan -- https://mail.python.org/mailman/listinfo/python-list
How to apply a self defined function in Pandas
I defined a function and apply it to a column in Pandas. But it does not return correct values. I am trying to test which url in a column full of url to see which one can be connected to or not def connect(url): try: urllib.request.urlopen(url) return True except: return False df['URL'] = df.apply(lambda x: connect(df['URL']), axis=1) I ran without any error, but did not return any true. I just could not find any error with it. Can anyone try and find out why Regards, David -- https://mail.python.org/mailman/listinfo/python-list
Re: How to apply a self defined function in Pandas
On 2021-10-31 17:25, Shaozhong SHI wrote: I defined a function and apply it to a column in Pandas. But it does not return correct values. I am trying to test which url in a column full of url to see which one can be connected to or not def connect(url): try: urllib.request.urlopen(url) return True except: return False df['URL'] = df.apply(lambda x: connect(df['URL']), axis=1) I ran without any error, but did not return any true. I just could not find any error with it. Can anyone try and find out why You're passing a function to '.apply'. That has one argument,' x'. But what is the function doing with that argument? Nothing. The function is just returning the result of connect(df['URL']). df['URL'] is a column, so you're passing a column to '.urlopen', which, of course, it doesn't understand. So 'connect' returns False. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to apply a self defined function in Pandas
> df['URL'] = df.apply(lambda x: connect(df['URL']), axis=1) I think you need axis=0. Or use the Series, df['URL'] = df.URL.apply(connect) -- https://mail.python.org/mailman/listinfo/python-list
Re: How to apply a self defined function in Pandas
On Sunday, 31 October 2021, Albert-Jan Roskam wrote: > > > > df['URL'] = df.apply(lambda x: connect(df['URL']), axis=1) > > > I think you need axis=0. Or use the Series, df['URL'] = > df.URL.apply(connect) > Any details? I will try and let you know. Regards, David -- https://mail.python.org/mailman/listinfo/python-list
Re: How to apply a self defined function in Pandas
On Sunday, 31 October 2021, MRAB wrote: > On 2021-10-31 17:25, Shaozhong SHI wrote: > >> I defined a function and apply it to a column in Pandas. But it does not >> return correct values. >> >> I am trying to test which url in a column full of url to see which one can >> be connected to or not >> >> def connect(url): >> try: >> urllib.request.urlopen(url) >> return True >> except: >> return False >> >> df['URL'] = df.apply(lambda x: connect(df['URL']), axis=1) >> >> I ran without any error, but did not return any true. >> >> I just could not find any error with it. >> >> Can anyone try and find out why >> >> You're passing a function to '.apply'. That has one argument,' x'. > > But what is the function doing with that argument? > > Nothing. > > The function is just returning the result of connect(df['URL']). > > df['URL'] is a column, so you're passing a column to '.urlopen', which, of > course, it doesn't understand. > > So 'connect' returns False. > > Please expand on how. David > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: How to apply a self defined function in Pandas
On 2021-10-31 18:48, Shaozhong SHI wrote: On Sunday, 31 October 2021, MRAB wrote: On 2021-10-31 17:25, Shaozhong SHI wrote: I defined a function and apply it to a column in Pandas. But it does not return correct values. I am trying to test which url in a column full of url to see which one can be connected to or not def connect(url): try: urllib.request.urlopen(url) return True except: return False df['URL'] = df.apply(lambda x: connect(df['URL']), axis=1) I ran without any error, but did not return any true. I just could not find any error with it. Can anyone try and find out why You're passing a function to '.apply'. That has one argument,' x'. But what is the function doing with that argument? Nothing. The function is just returning the result of connect(df['URL']). df['URL'] is a column, so you're passing a column to '.urlopen', which, of course, it doesn't understand. So 'connect' returns False. Please expand on how. It's as simple as passing 'connect' to '.apply' as the first argument. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to apply a self defined function in Pandas
On Sun, 31 Oct 2021 at 19:28, MRAB wrote: > On 2021-10-31 18:48, Shaozhong SHI wrote: > > > > On Sunday, 31 October 2021, MRAB wrote: > > > > On 2021-10-31 17:25, Shaozhong SHI wrote: > > > > I defined a function and apply it to a column in Pandas. But > > it does not > > return correct values. > > > > I am trying to test which url in a column full of url to see > > which one can > > be connected to or not > > > > def connect(url): > > try: > > urllib.request.urlopen(url) > > return True > > except: > > return False > > > > df['URL'] = df.apply(lambda x: connect(df['URL']), axis=1) > > > > I ran without any error, but did not return any true. > > > > I just could not find any error with it. > > > > Can anyone try and find out why > > > > You're passing a function to '.apply'. That has one argument,' x'. > > > > But what is the function doing with that argument? > > > > Nothing. > > > > The function is just returning the result of connect(df['URL']). > > > > df['URL'] is a column, so you're passing a column to '.urlopen', > > which, of course, it doesn't understand. > > > > So 'connect' returns False. > > > > > > Please expand on how. > > > It's as simple as passing 'connect' to '.apply' as the first argument. > Well, can you expand the the simplicity? Regards, David > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: How to apply a self defined function in Pandas
Am Sun, Oct 31, 2021 at 07:52:18PM + schrieb Shaozhong SHI: > Well, can you expand the the simplicity? Not sure how expanding is going to help but here's one way to do it: Python 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] on linux Type "help", "copyright", "credits" or "license" for more information. >>> list('simplicity') ['s', 'i', 'm', 'p', 'l', 'i', 'c', 'i', 't', 'y'] >>> Best, Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B -- https://mail.python.org/mailman/listinfo/python-list
Re: How to apply a self defined function in Pandas
On Sun, 31 Oct 2021 at 18:42, Shaozhong SHI wrote: > > > On Sunday, 31 October 2021, Albert-Jan Roskam > wrote: > >> >> >> > df['URL'] = df.apply(lambda x: connect(df['URL']), axis=1) >> >> >> I think you need axis=0. Or use the Series, df['URL'] = >> df.URL.apply(connect) >> > > Just experimented with your suggestion, but have not seen any difference. > Regards, David -- https://mail.python.org/mailman/listinfo/python-list
Python C API: how to mark a type as subclass of another type
I have two types declared as PyTypeObject PyX_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) etc. How can I mark one of the types as subclass of the other one? I tried to use tp_base but it didn't work. -- https://mail.python.org/mailman/listinfo/python-list
RE: How to apply a self defined function in Pandas
When people post multiple comments and partial answers and the reply every time is to ask for more; there may be a disconnect. Some assume that the person is just stuck but generally can go forward with a little hint. But when you keep being asked for more, maybe it means they want you to do it for them, as in some asking about HW. I am not joining this one. 😉 -Original Message- From: Python-list On Behalf Of Karsten Hilbert Sent: Sunday, October 31, 2021 4:00 PM To: python-list@python.org Subject: Re: How to apply a self defined function in Pandas Am Sun, Oct 31, 2021 at 07:52:18PM + schrieb Shaozhong SHI: > Well, can you expand the the simplicity? Not sure how expanding is going to help but here's one way to do it: Python 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] on linux Type "help", "copyright", "credits" or "license" for more information. >>> list('simplicity') ['s', 'i', 'm', 'p', 'l', 'i', 'c', 'i', 't', 'y'] >>> Best, Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list