Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.python > #5713

Re: [Python-de] Verstaendnisproblem

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Peter Otten <__peter__@web.de>
Newsgroups de.comp.lang.python
Subject Re: [Python-de] Verstaendnisproblem
Date Fri, 12 Feb 2021 17:30:04 +0100
Lines 60
Message-ID <mailman.1114.1613147414.7193.python-de@python.org> (permalink)
References <2763401.e9J7NaK4W3@host.fritz.box> <107543700.nniJfEyVGO@host.fritz.box> <bff5cf57-b57b-300b-17d8-5390cd8bb3da@web.de> <5436893.DvuYhMxLoT@host.fritz.box> <8c5a698d-6083-1244-f205-c843af42ef02@sschwarzer.net> <0f1c0b5f-3aa9-9576-0ac2-b19483be4dfd@web.de>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de qWTGjjLY/ol5VyMz7Lk8DgKJR5LFuZG3dRswstBOV+Mw==
Return-Path <gcpgg-python-de@m.gmane-mx.org>
X-Original-To python-de@python.org
Delivered-To python-de@mail.python.org
Authentication-Results mail.python.org; dkim=none reason="no signature"; dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Injected-Via-Gmane http://gmane.org/
User-Agent Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.7.1
In-Reply-To <8c5a698d-6083-1244-f205-c843af42ef02@sschwarzer.net>
Content-Language en-US
X-BeenThere python-de@python.org
X-Mailman-Version 2.1.34
Precedence list
List-Id Die Deutsche Python Mailingliste <python-de.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-de>, <mailto:python-de-request@python.org?subject=unsubscribe>
List-Archive <https://mail.python.org/pipermail/python-de/>
List-Post <mailto:python-de@python.org>
List-Help <mailto:python-de-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-de>, <mailto:python-de-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <0f1c0b5f-3aa9-9576-0ac2-b19483be4dfd@web.de>
X-Mailman-Original-References <2763401.e9J7NaK4W3@host.fritz.box> <107543700.nniJfEyVGO@host.fritz.box> <bff5cf57-b57b-300b-17d8-5390cd8bb3da@web.de> <5436893.DvuYhMxLoT@host.fritz.box> <8c5a698d-6083-1244-f205-c843af42ef02@sschwarzer.net>
Xref csiph.com de.comp.lang.python:5713

Show key headers only | View raw


On 12/02/2021 16:07, Stefan Schwarzer wrote:
> On 2021-02-12 15:29, eilfh wrote:
>> Am Donnerstag, 11. Februar 2021, 18:48:23 CET schrieb Peter Otten:
>> Hallo, Peter
>>
>> danke für Deine Antwort.
>>
>> Das war das fehlende Puzzle in meinem Programm
>>
>>>   >>> x
>>>
>>> 0    4
>>> Name: B, dtype: int64
>>>
>>>   >>> type(x)
>>>
>>> <class 'pandas.core.series.Series'>
>>>
>>>
>>> kannst Du einfach entpacken
>>>
>>>   >>> [y] = x
>>>   >>> y
>>>
>>> 4
>>
>>
>> um ehrlich zu sein, ich versteh's zwar nicht,
>> aber es läuft und erfüllte genau den Zweck
> 
> Falls du `[y] = x` meinst, kann ich mir vorstellen, dass das
> komisch aussieht. Das ist sogenanntes implizites "Tuple
> unpacking", hier vielleicht eher "List unpacking". Du kannst
> das auch als `y = x[0]` schreiben; ich denke, das ist klarer.

Wenn x vom Typ tuple oder list ist, gerne; aber pandas ist ziemlich 
komplex und hält immer eine Überraschung bereit:

 >>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
 >>> ser = df.loc[df.A == 1, "B"]
 >>> ser[0]
4

Scheint zu funktionieren, ist aber Zufall:

 >>> ser = df.loc[df.A == 2, "B"]
 >>> ser[0]
Traceback (most recent call last):
[...]
KeyError: 0

Mit Unpacking:

 >>> [y] = ser
 >>> y
5

D. h. eine Series verhält sich beim Iterieren wie eine Liste, beim 
Lookup wie ein dict.

Back to de.comp.lang.python | Previous | Next | Find similar


Thread

Re: [Python-de] Verstaendnisproblem Peter Otten <__peter__@web.de> - 2021-02-12 17:30 +0100

csiph-web