Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > fr.comp.lang.python > #3446
| From | carboleum <c4rboleum-NOSPAM@gmail.com> |
|---|---|
| Newsgroups | fr.comp.lang.python |
| Subject | Re: pandas switch-on switch-off |
| Date | 2021-04-02 12:25 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <s46rfk$kkb$1@dont-email.me> (permalink) |
| References | <s46nio$r79$1@dont-email.me> <6066e50d$0$32516$426a74cc@news.free.fr> |
On 2/04/21 11:34, Damien Wyart wrote:
> * carboleum <c4rboleum-NOSPAM@gmail.com> in fr.comp.lang.python:
>> Dans mon dataframe, j'ai une colonne "on" qui allume la lumière et une
>> colonne "off" qui éteint la lumière.
>
>> Quelqu'un connais la fonction (si elle existe ?) qui renvoie la
>> colonne "lumière allumée" ?
>
>> on off res
>> 0 0 0 0
>> 1 0 0 0
>> 2 1 0 1
>> 3 0 0 1
>> 4 0 1 0
>> 5 0 0 0
>> 6 0 0 0
>> 7 0 1 0
>> 8 0 0 0
>> 9 1 0 1
>> 10 0 0 1
>> 11 1 0 1
>> 12 0 0 1
>> 13 0 1 0
>> 14 0 1 0
>> 15 0 0 0
>
> Avant de répondre, je pense qu'il manque quelques infos :
>
> - la ligne 10 donne un résultat de 1 alors qu'il n'y a n'y extinction ni
> allumage donc je pense que le résultat dépend aussi d'un état initial
> (qui n'est pas affiché ici)
si, il y a un allumage en 9.
Je me rends compte qu mon énoncé est ambigü
On a deux boutons poussoirs (on et off) (le on sert à allumer, le off à
éteindre la même lumière). Au temps t=0, je fais rien, la lumière est
éteinte. En t=1, idem. En t=2, je pousse sur "on",la lumière s'allume.
En t=3, je fais rien, la lumière reste allumée. En t=4, je pousse sur
"off", la lumière s'éteint. etc.
La difficulté est que je dois reprendre le résultat précédent afin de
déterminer le résultat actuel.
Sinon, un simple boucle peut faire l'affaire:
for i in df.index:
if df['on'][i]:
df['out'][i] = True
elif df['off'][i]:
df['out'][i] = False
elif i == 0:
df['out'][i] = False
else:
df['out'][i] = df['out'][i-1]
mais je trouve ça très peu élégant.
>
> - est-on certain que on et off sont mutuellement exclusifs ? S'il
> y a une erreur dans les données et que les deux sont à 1 est-ce que le
> résultat doit être 0 ou 1 ?
>
Je décide qu'en cas d'allumage et extinction simultané, c'est
l'extinction qui est prioritaire, la lampe s'éteint (1 1 -> 0)
16 0 0 0
17 1 0 1
18 1 1 0
19 0 0 0
Back to fr.comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
pandas switch-on switch-off carboleum <c4rboleum-NOSPAM@gmail.com> - 2021-04-02 11:19 +0200
Re: pandas switch-on switch-off Damien Wyart <damien.wyart@free.fr> - 2021-04-02 11:34 +0200
Re: pandas switch-on switch-off carboleum <c4rboleum-NOSPAM@gmail.com> - 2021-04-02 12:25 +0200
Re: pandas switch-on switch-off Damien Wyart <damien.wyart@free.fr> - 2021-04-02 16:47 +0200
Re: pandas switch-on switch-off carboleum <c4rboleum-NOSPAM@gmail.com> - 2021-04-02 18:29 +0200
Re: pandas switch-on switch-off Nicolas <nicolasp@aaton.com> - 2021-04-06 08:53 +0200
Re: pandas switch-on switch-off Damien Wyart <damien.wyart@free.fr> - 2021-04-06 18:42 +0200
Re: pandas switch-on switch-off Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2021-04-06 22:00 +0200
Re: pandas switch-on switch-off Nicolas <nicolasp@aaton.com> - 2021-04-07 08:50 +0200
Re: pandas switch-on switch-off carboleum <c4rboleum-NOSPAM@gmail.com> - 2021-07-09 15:52 +0200
Re: pandas switch-on switch-off Damien Wyart <damien.wyart@free.fr> - 2021-07-15 11:23 +0200
Re: pandas switch-on switch-off Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2021-07-15 13:20 +0200
Re: pandas switch-on switch-off Carboléüm <c4rboleumNOSPAM@gmail.com> - 2021-07-16 10:13 +0200
Re: pandas switch-on switch-off Carboleum <c4rboleum**NOSPAM**@gmail.com.invalid> - 2022-04-03 14:51 +0200
Re: pandas switch-on switch-off Damien Wyart <damien.wyart@free.fr> - 2022-04-12 07:34 +0200
csiph-web