RE: How to apply a self defined function in Pandas

2021-10-31 Thread Avi Gross via Python-list
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

Re: How to apply a self defined function in Pandas

2021-10-31 Thread Shaozhong SHI
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 experime

Re: How to apply a self defined function in Pandas

2021-10-31 Thread Karsten Hilbert
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", "copyr

Re: How to apply a self defined function in Pandas

2021-10-31 Thread Shaozhong SHI
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 > >

Re: How to apply a self defined function in Pandas

2021-10-31 Thread MRAB
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

Re: How to apply a self defined function in Pandas

2021-10-31 Thread Shaozhong SHI
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 >

Re: How to apply a self defined function in Pandas

2021-10-31 Thread Shaozhong SHI
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/ma

Re: How to apply a self defined function in Pandas

2021-10-31 Thread Albert-Jan Roskam
> 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

2021-10-31 Thread MRAB
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.urlope

How to apply a self defined function in Pandas

2021-10-31 Thread Shaozhong SHI
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: