Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Although the moon is smaller than the earth, it is farther away.


devel / comp.lang.python / Re: How to apply a self defined function in Pandas

SubjectAuthor
o Re: How to apply a self defined function in PandasShaozhong SHI

1
Re: How to apply a self defined function in Pandas

<mailman.158.1635709951.23718.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=20294&group=comp.lang.python#20294

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: shishaozhong@gmail.com (Shaozhong SHI)
Newsgroups: comp.lang.python
Subject: Re: How to apply a self defined function in Pandas
Date: Sun, 31 Oct 2021 19:52:18 +0000
Lines: 58
Message-ID: <mailman.158.1635709951.23718.python-list@python.org>
References: <CA+i5Jwa597U8rst0AzMyksqHYUPO98KHXyB2emnGb7W466cvAQ@mail.gmail.com>
<CA+i5JwYTsp-t5LUNJ9237DFCDqNy+0yDsi3Eir=nyVWccO=epg@mail.gmail.com>
<fd667721-c23d-a0a0-3a12-c56b90afa0c3@mrabarnett.plus.com>
<CA+i5JwZfNepArX5DM5B4AtM=NdtU_viBLAMrU4xRx-JtKr+wGg@mail.gmail.com>
<368fea32-2066-bd5a-8f43-4753fc39c849@mrabarnett.plus.com>
<CA+i5JwYDpRVnVK4t-H2DL2_jugVu3X3QBWDsutACWUfsCTdiKw@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de eIm6u1XsgQDYSXmSkmh4BA6AVhJ73KcyMCLe48iJA/Dw==
Return-Path: <shishaozhong@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=o012TANq;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'def': 0.04; 'sun,': 0.07;
'cc:addr:python-list': 0.09; 'skip:\xc2 20': 0.09; 'values.':
0.09; '&gt;': 0.14; 'url:mailman': 0.15; 'column': 0.16; 'false.':
0.16; 'nothing.': 0.16; 'pandas.': 0.16; 'understand.': 0.16;
'which,': 0.16; '\xc2\xa0be': 0.16; '\xc2\xa0but': 0.16;
'\xc2\xa0def': 0.16; '\xc2\xa0on': 0.16; '\xc2\xa0so': 0.16;
'wrote:': 0.16; 'october': 0.17; 'url': 0.19;
'cc:addr:python.org': 0.20; 'ran': 0.22; 'returns': 0.22;
'subject:How': 0.23; 'url-ip:188.166.95.178/32': 0.25; 'url-
ip:188.166.95/24': 0.25; 'url:listinfo': 0.25; 'cc:2**0': 0.25;
'url-ip:188.166/16': 0.25; 'anyone': 0.25; 'function': 0.27;
'error': 0.29; 'url-ip:188/8': 0.31; "doesn't": 0.32; 'expand':
0.32; 'returning': 0.32; 'message-id:@mail.gmail.com': 0.32;
'but': 0.32; 'header:In-Reply-To:1': 0.34; 'received:google.com':
0.34; 'trying': 0.35; 'from:addr:gmail.com': 0.35; "it's": 0.37;
'received:209.85': 0.37; 'could': 0.38; 'error,': 0.38;
'received:209': 0.39; 'received:209.85.208': 0.39; 'skip:u 20':
0.39; 'true.': 0.40; 'try': 0.40; 'true': 0.63; 'full': 0.64;
'8bit%:7': 0.67; '2021': 0.71; 'shi': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:cc; bh=+ulAqc6xKjQUUkkETtNnsDFL/38FBq4V8zIHWC5EyqE=;
b=o012TANqWbyNHI65X0GfLRNxKtsFCnUpzwOISC2GbPo2GZPqVfudLfBckcRIHutBZ2
9LNP6ri7qkriEqMpyQ/qTdXVYNe5BF2VizNIIbeV0frcuT7zhRHutdANg02wH4WZhR8N
ryAerrsgV+B6NELuRlGjEbxCLottAx5IskEwgN52jMP+KoRh+el7hsjsk1GGFv1LFymW
lbKQE9NxNcWpwkRuvw+0MrwDiS2TmJnlGGtP9PjiDreB9MLVp02ce2bgeWySwndV3sIN
zYKA00fX+W7LiXCYyPBKBd7NyHk4fmygrH9fwcw9KX+1/ZBqHhQIoPZwsRi2W+vtsBcP
CNnw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:cc;
bh=+ulAqc6xKjQUUkkETtNnsDFL/38FBq4V8zIHWC5EyqE=;
b=WMI81w8/MCLS1270xlf5iDfc51XykEH1mH+WKJmYTnfKjHsO7Yo6DoXaWdJsJ7X3gp
M7l73UMrUPkg3qNwAGQl3yF5tzEVAZNStTGielKZ6MdvpVP8SF3T5ahQmyLGw3KsErx+
yr79S8ZeALutN1bj4OhJhAJAcZgyLKlmw2yXzCRQrBfOJs63W39krF+gXBWxNnGQfrD/
yJeNstBg/WkaZULseRwMQdTsVXl3ZBPTvEqCVgQa/ficlPjWMt/9vTOS75F/X/HkNfFe
v/VJHQuBSqzunSuZTElwBvcqop/kiGqKmmYmMqFsUCMWfvMW33iXMDfnJZXOxo1FK02L
b2ig==
X-Gm-Message-State: AOAM531ivqE0EudJB4sxfihmNqb5s49RPAsGcMFbscwH4x2J5Hc61GwW
10jhIDfV0tSnpkB4ffVMbnjepyiv69JTgjkAHDp0K6kY
X-Google-Smtp-Source: ABdhPJw3xzppmQY8OVXnMrCjfTSqOIvxWKJWT9gAPbQoCjZym8Zl0UgIjpkSnHqhTgMYx6LWu9BbmS+pawkzXHCDsYw=
X-Received: by 2002:a05:6402:4412:: with SMTP id
y18mr34174915eda.275.1635709949723;
Sun, 31 Oct 2021 12:52:29 -0700 (PDT)
In-Reply-To: <368fea32-2066-bd5a-8f43-4753fc39c849@mrabarnett.plus.com>
X-Content-Filtered-By: Mailman/MimeDel 2.1.35
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.35
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CA+i5JwYDpRVnVK4t-H2DL2_jugVu3X3QBWDsutACWUfsCTdiKw@mail.gmail.com>
X-Mailman-Original-References: <CA+i5Jwa597U8rst0AzMyksqHYUPO98KHXyB2emnGb7W466cvAQ@mail.gmail.com>
<CA+i5JwYTsp-t5LUNJ9237DFCDqNy+0yDsi3Eir=nyVWccO=epg@mail.gmail.com>
<fd667721-c23d-a0a0-3a12-c56b90afa0c3@mrabarnett.plus.com>
<CA+i5JwZfNepArX5DM5B4AtM=NdtU_viBLAMrU4xRx-JtKr+wGg@mail.gmail.com>
<368fea32-2066-bd5a-8f43-4753fc39c849@mrabarnett.plus.com>
 by: Shaozhong SHI - Sun, 31 Oct 2021 19:52 UTC

On Sun, 31 Oct 2021 at 19:28, MRAB <python@mrabarnett.plus.com> wrote:

> On 2021-10-31 18:48, Shaozhong SHI wrote:
> >
> > On Sunday, 31 October 2021, MRAB <python@mrabarnett.plus.com> 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
>


devel / comp.lang.python / Re: How to apply a self defined function in Pandas

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor