Computations on pandas dataframes

2018-05-25 Thread junkaccount36
Hi, Python newbie here. I need help with the following two tasks I need to accomplish using Python: Creating a matrix of rolling variances I have a pandas data frame of six columns, I would like to iteratively compute the variance along each column. Since I am a newbi

Re: cProfile, timed call tree

2018-05-25 Thread dieter
Nico Schlömer writes: > From what I understand about the Python profilers, the type of information > you get from a stats object is > > * How much time was spent in function X, > * what the callers and callees of function X are, and > * and bunch of meta info about function X. > > With the

Re: Raw string statement (proposal)

2018-05-25 Thread Mikhail V
On Fri, May 25, 2018 at 1:15 PM, bartc wrote: > On 25/05/2018 05:34, Mikhail V wrote: > > I had one big problem with your proposal, which is that I couldn't make head > or tail of your syntax. Such a thing should be immediately obvious. > > (In your first two examples, what IS the exact string th

Re: Enums: making a single enum

2018-05-25 Thread Chris Angelico
On Sat, May 26, 2018 at 3:07 PM, Ian Kelly wrote: > On Fri, May 25, 2018 at 11:00 PM, Chris Angelico wrote: >> On Sat, May 26, 2018 at 2:46 PM, Steven D'Aprano >> wrote: >>> Am I silly for wanting to make a single enum? >>> >>> I have a three-state flag, True, False or Maybe. Is is confusing or

Re: Enums: making a single enum

2018-05-25 Thread Ian Kelly
On Fri, May 25, 2018 at 11:00 PM, Chris Angelico wrote: > On Sat, May 26, 2018 at 2:46 PM, Steven D'Aprano > wrote: >> Am I silly for wanting to make a single enum? >> >> I have a three-state flag, True, False or Maybe. Is is confusing or bad >> practice to make a single enum for the Maybe case?

Re: Enums: making a single enum

2018-05-25 Thread Chris Angelico
On Sat, May 26, 2018 at 2:46 PM, Steven D'Aprano wrote: > Am I silly for wanting to make a single enum? > > I have a three-state flag, True, False or Maybe. Is is confusing or bad > practice to make a single enum for the Maybe case? > > > from enum import Enum > class State(Enum): > Maybe = 2

Enums: making a single enum

2018-05-25 Thread Steven D'Aprano
Am I silly for wanting to make a single enum? I have a three-state flag, True, False or Maybe. Is is confusing or bad practice to make a single enum for the Maybe case? from enum import Enum class State(Enum): Maybe = 2 Maybe = State.Maybe del State Is there a better way of handling a

Re: List replication operator

2018-05-25 Thread Gregory Ewing
bartc wrote: /The/ matrix multiplication operator? In which language? And what was wrong with "*"? It seems you're unaware that Python *already* has an '@' operator. It was added specifically so that numpy could use it for matrix multiplication. A new operator was needed because numpy already

Re: List replication operator

2018-05-25 Thread Gregory Ewing
Dennis Lee Bieber wrote: @ requires use of the weaker/shorter "ring finger" on (for me) the weaker left hand. But... choosing an operator on that basis would be discriminating against left-handed people! -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: List replication operator

2018-05-25 Thread Steven D'Aprano
On Fri, 25 May 2018 09:58:19 -0700, Rob Gaddi wrote: [...] >> This is a frequent, recurring pain point. Experienced programmers >> forget how confusing the behaviour of * is because they're so used to >> the execution model. They forget that writing a list comp is not even >> close to obvious, not

Re: Some Issues on Tagging Text

2018-05-25 Thread MRAB
On 2018-05-25 23:24, Cameron Simpson wrote: [snip] You can reduce that list by generating the "wordlist" form from something smaller: base_phrases = ["Kilauea volcano", "government of Mexico", "Hawaii"] wordlist = [ (base_phrase, " ".join([word + "/TAG" for word in base_phrase.split

Re: Some Issues on Tagging Text

2018-05-25 Thread Ben Finney
Cameron Simpson writes: > On 25May2018 04:23, Subhabrata Banerjee wrote: > >On Friday, May 25, 2018 at 3:59:57 AM UTC+5:30, Cameron Simpson wrote: > >> If you want to solve this problem with a programme you must first > >> clearly define what makes an unwanted tag "unwanted". [...] > > > >By unw

Re: why do I get syntax error on if : break

2018-05-25 Thread Dan Stromberg
On Thu, May 24, 2018 at 7:12 PM, wrote: > here is the code, i keep getting an error, "break outside loop". if it is > false just exit function > > > def d(idx): > if type(idx) != int: > break > > d('k') Not what you asked, but I believe pylint recommends using not isinstance instead

Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-25 Thread boB Stepp
On Fri, May 25, 2018 at 6:04 AM, Paul St George wrote: > I am using the Python Imaging Library (PIL), Python 2 and Raspberry Pi 3 B+ > > My code is simply: > > from PIL import Image > > im = Image.open(‘somepic.jpg’) > im.show() # display image > > > But the show() method looks for the

Re: List replication operator

2018-05-25 Thread Steven D'Aprano
On Fri, 25 May 2018 13:05:01 -0400, Dennis Lee Bieber wrote: > Let me play devil's advocate... and propose a simple change, with no > new operators... > > sl = [] * n #current behavior > dl = n * [] #deep copy behavior n*[] is already supported. You will suddenly chang

Re: List replication operator

2018-05-25 Thread Steven D'Aprano
On Sat, 26 May 2018 02:58:06 +1000, Chris Angelico wrote: > Your mail/news client might choose to represent configure.ac as a link, > since ".ac" is a valid TLD. Isn't *everything* a valid TLD now? For the right price, at least. -- Steve -- https://mail.python.org/mailman/listinfo/python-l

Re: Some Issues on Tagging Text

2018-05-25 Thread Cameron Simpson
On 25May2018 04:23, Subhabrata Banerjee wrote: On Friday, May 25, 2018 at 3:59:57 AM UTC+5:30, Cameron Simpson wrote: On 24May2018 03:13, wrote: >I have a text as, > >"Hawaii volcano generates toxic gas plume called laze PAHOA: The eruption of Kilauea volcano in Hawaii sparked new safety warni

Re: List replication operator

2018-05-25 Thread MRAB
On 2018-05-25 18:05, Dennis Lee Bieber wrote: On Fri, 25 May 2018 15:40:41 + (UTC), Steven D'Aprano declaimed the following: On Fri, 25 May 2018 22:46:37 +1000, Chris Angelico wrote: We've already had a suggestion for [[]]@5 and that should deal with that issue. Steven is proposing "mult

Re: List replication operator

2018-05-25 Thread Rob Gaddi
On 05/25/2018 10:13 AM, bartc wrote: On 25/05/2018 17:58, Rob Gaddi wrote: So, in the spirit of explicit being better than implicit, please assume that for actual implementation replicate would be a static method of actual list, rather than the conveniently executable hackjob below. _list =

Re: List replication operator

2018-05-25 Thread bartc
On 25/05/2018 17:58, Rob Gaddi wrote: So, in the spirit of explicit being better than implicit, please assume that for actual implementation replicate would be a static method of actual list, rather than the conveniently executable hackjob below. _list = list _nodefault = object() class list

Re: List replication operator

2018-05-25 Thread Rob Gaddi
On 05/25/2018 04:53 AM, Steven D'Aprano wrote: On Fri, 25 May 2018 09:28:01 +0200, Peter Otten wrote: Yet another arcanum to learn for beginners with little return. If you cannot refrain from tinkering with the language at least concentrate on the features with broad application. Thank you. B

Re: List replication operator

2018-05-25 Thread Chris Angelico
On Sat, May 26, 2018 at 2:43 AM, bartc wrote: > On 25/05/2018 17:11, Alexandre Brault wrote: >> >> >> >> On 2018-05-25 11:40 AM, bartc wrote: >>> >>> On 25/05/2018 16:27, Chris Angelico wrote: You're way WAY too late to debate the matrix multiplication operator. >>> >>> >>> /The/ matrix

Re: List replication operator

2018-05-25 Thread Steven D'Aprano
On Fri, 25 May 2018 17:12:12 +0100, bartc wrote: > On 25/05/2018 16:40, Steven D'Aprano wrote: [...] >> On the other hand, it is arguable that what we really need is a >> standard function to return an N-dimensional array/list: >> >> # return a 3x4x5x6 4-D list initialised to all zeroes arr = >>

Re: List replication operator

2018-05-25 Thread bartc
On 25/05/2018 17:11, Alexandre Brault wrote: On 2018-05-25 11:40 AM, bartc wrote: On 25/05/2018 16:27, Chris Angelico wrote: You're way WAY too late to debate the matrix multiplication operator. /The/ matrix multiplication operator? In which language? And what was wrong with "*"? In Pyth

Re: List replication operator

2018-05-25 Thread Steven D'Aprano
On Fri, 25 May 2018 11:59:38 -0400, Dennis Lee Bieber wrote: > What is your definition of a multi-dimensional array -- I tend to think > of them as pre-declared sizes; not the variable (row|column) lengths > possible when using nested lists. Any fixed size array can be implemented using a

Re: "Data blocks" syntax specification draft

2018-05-25 Thread Steven D'Aprano
On Tue, 22 May 2018 08:01:05 +0200, Christian Gollwitzer wrote: >>> If a block of static data is large enough to start to be ugly, a >>> common approach is to load the data from some other file, in a >>> language which is designed around structured data. [...] > Thing is, you can do it already no

Re: List replication operator

2018-05-25 Thread Alexandre Brault
On 2018-05-25 11:40 AM, bartc wrote: > On 25/05/2018 16:27, Chris Angelico wrote: >> You're way WAY too late to debate the matrix multiplication operator. > > /The/ matrix multiplication operator? > > In which language? And what was wrong with "*"? > In Python, the language we're discussing right

Re: List replication operator

2018-05-25 Thread bartc
On 25/05/2018 16:40, Steven D'Aprano wrote: On Fri, 25 May 2018 22:46:37 +1000, Chris Angelico wrote: We've already had a suggestion for [[]]@5 and that should deal with that issue. Steven is proposing "multiply by copying" as an alternative to "multiply by referencing", so an alternative multi

Re: List replication operator

2018-05-25 Thread Chris Angelico
On Sat, May 26, 2018 at 1:40 AM, bartc wrote: > On 25/05/2018 16:27, Chris Angelico wrote: >> >> On Fri, May 25, 2018 at 10:58 PM, bartc wrote: >>> >>> I'm in general not in favour of piling in special symbols into a language >>> just to solve some obscure or rare problem. >>> >>> As I went on to

Re: List replication operator

2018-05-25 Thread Chris Angelico
On Sat, May 26, 2018 at 1:46 AM, Steven D'Aprano wrote: > On Fri, 25 May 2018 18:06:00 +1000, Chris Angelico wrote: > >> Downside: while it's all very well to say that this is equivalent to >> copy.deepcopy(), that would imply replicating copy.deepcopy's semantics >> in the core list type (unless

Undocumented unescape() method in HTMLParser?

2018-05-25 Thread Tobiah
I came across its usage in StackOverflow somewhere, but didn't see it in the docs. I'm using 2.7. I needed it while writing a class for generating text documents out of HTML documents for attaching to emails, which lowers spam scores. I lifted the basis for this from the top answer here: https

Re: List replication operator

2018-05-25 Thread Steven D'Aprano
On Fri, 25 May 2018 18:06:00 +1000, Chris Angelico wrote: > Downside: while it's all very well to say that this is equivalent to > copy.deepcopy(), that would imply replicating copy.deepcopy's semantics > in the core list type (unless it's actually literally defined as > importing a module and cal

Re: List replication operator

2018-05-25 Thread Steven D'Aprano
On Fri, 25 May 2018 18:06:00 +1000, Chris Angelico wrote: > Downside: while it's all very well to say that this is equivalent to > copy.deepcopy(), that would imply replicating copy.deepcopy's semantics > in the core list type (unless it's actually literally defined as > importing a module and cal

Re: List replication operator

2018-05-25 Thread bartc
On 25/05/2018 16:27, Chris Angelico wrote: On Fri, May 25, 2018 at 10:58 PM, bartc wrote: I'm in general not in favour of piling in special symbols into a language just to solve some obscure or rare problem. As I went on to demonstrate, function-like syntax (or even actual functions) could do

Re: List replication operator

2018-05-25 Thread Steven D'Aprano
On Fri, 25 May 2018 22:46:37 +1000, Chris Angelico wrote: > We've already had a suggestion for [[]]@5 and that should deal with that > issue. Steven is proposing "multiply by copying" as an alternative to > "multiply by referencing", so an alternative multiplication operator > should fit that corr

Re: List replication operator

2018-05-25 Thread Steven D'Aprano
On Fri, 25 May 2018 13:58:03 +0100, bartc wrote: > As for '@', if a variable name can come before it /and/ after it, and > either or both can be dotted, wouldn't that cause it to be highlighted > as an email address in many circumstances? Such as in code posted here. Sure. And x/y might be forma

Re: List replication operator

2018-05-25 Thread Chris Angelico
On Fri, May 25, 2018 at 10:58 PM, bartc wrote: > I'm in general not in favour of piling in special symbols into a language > just to solve some obscure or rare problem. > > As I went on to demonstrate, function-like syntax (or even actual functions) > could do that job better, by describing what t

Re: convert a string to a variable

2018-05-25 Thread Ned Batchelder
On 5/25/18 9:52 AM, brucegoodst...@gmail.com wrote: On Friday, May 25, 2018 at 8:06:31 AM UTC-4, Ned Batchelder wrote: On 5/24/18 6:54 PM, bruceg113...@gmail.com wrote: I am trying to convert a string to a variable. I got cases 1 & 2 to work, but not cases 3 & 4. The print statement in cases

Re: convert a string to a variable

2018-05-25 Thread brucegoodstein
On Friday, May 25, 2018 at 8:06:31 AM UTC-4, Ned Batchelder wrote: > On 5/24/18 6:54 PM, bruceg113...@gmail.com wrote: > > I am trying to convert a string to a variable. > > > > I got cases 1 & 2 to work, but not cases 3 & 4. > > > > The print statement in cases 3 & 4 reports the following: > >

Re: convert a string to a variable

2018-05-25 Thread brucegoodstein
On Friday, May 25, 2018 at 1:56:14 AM UTC-4, dieter wrote: > bruceg113...@gmail.com writes: > > > I am trying to convert a string to a variable. > > > > I got cases 1 & 2 to work, but not cases 3 & 4. > > > > The print statement in cases 3 & 4 reports the following: > > builtins.AttributeError

EuroPython 2018: Talk voting is open

2018-05-25 Thread M.-A. Lemburg
At EuroPython, we let our attendees have a significant say in the selection of the sessions which are presented at the conference. We call this “talk voting” - attendees can tell us which submitted talks they’d like to see at the conference. To be eligible to vote for talks, you need to be a submi

Re: List replication operator

2018-05-25 Thread bartc
On 25/05/2018 13:46, Chris Angelico wrote: On Fri, May 25, 2018 at 10:36 PM, bartc wrote: On 24/05/2018 19:17, Steven D'Aprano wrote: But what do people think about proposing a new list replication with copy operator? [[]]**5 would return a new list consisting of five shallow copies o

Re: List replication operator

2018-05-25 Thread Chris Angelico
On Fri, May 25, 2018 at 10:36 PM, bartc wrote: > On 24/05/2018 19:17, Steven D'Aprano wrote: > >> But what do people think about proposing a new list replication with copy >> operator? >> >> [[]]**5 >> >> would return a new list consisting of five shallow copies of the inner >> list. >> >> Th

Re: List replication operator

2018-05-25 Thread bartc
On 25/05/2018 13:36, bartc wrote: Of course you have to implement dupllist(), but you'd have to implement ** too, and that is harder. For this specific example, it can just be: def dupllist(x,n):     return [x[0].copy() for _ in range(n)] On 25/05/2018 03:25, Steven D'Aprano wrote: > You m

Re: List replication operator

2018-05-25 Thread bartc
On 24/05/2018 19:17, Steven D'Aprano wrote: But what do people think about proposing a new list replication with copy operator? [[]]**5 would return a new list consisting of five shallow copies of the inner list. Thoughts? Choice of ** doesn't seem right for a start, as it suggests it

cProfile, timed call tree

2018-05-25 Thread Nico Schlömer
Hi everyone, >From what I understand about the Python profilers, the type of information you get from a stats object is * How much time was spent in function X, * what the callers and callees of function X are, and * and bunch of meta info about function X. With the program ``` def prime(n

Re: convert a string to a variable

2018-05-25 Thread Ned Batchelder
On 5/24/18 6:54 PM, bruceg113...@gmail.com wrote: I am trying to convert a string to a variable. I got cases 1 & 2 to work, but not cases 3 & 4. The print statement in cases 3 & 4 reports the following: builtins.AttributeError: type object 'animal' has no attribute 'tiger' I am stuck

Re: Some Issues on Tagging Text

2018-05-25 Thread Richard Damon
On 5/25/18 7:23 AM, subhabangal...@gmail.com wrote: > On Friday, May 25, 2018 at 3:59:57 AM UTC+5:30, Cameron Simpson wrote: >> First up, thank you for a well described problem! Remarks inline below. >> >> On 24May2018 03:13, wrote: >>> I have a text as, >>> >>> "Hawaii volcano generates toxic gas

Re: List replication operator

2018-05-25 Thread Steven D'Aprano
On Fri, 25 May 2018 09:28:01 +0200, Peter Otten wrote: > Yet another arcanum to learn for beginners with little return. If you > cannot refrain from tinkering with the language at least concentrate on > the features with broad application. Thank you. Broader than multi-dimensional arrays? There a

Re: List replication operator

2018-05-25 Thread Steven D'Aprano
On Fri, 25 May 2018 11:48:49 +0100, Ben Bacarisse wrote: > Another way of looking at it would be in terms of evaluation rather than > copying. [] evaluates to a new list object, so if there were an > alternate version of L * n (for the sake of argument L ** n) that > evaluated the list expression

The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-25 Thread Paul St George
I am using the Python Imaging Library (PIL), Python 2 and Raspberry Pi 3 B+ My code is simply:     from PIL import Image     im = Image.open(‘somepic.jpg’)     im.show() # display image But the show() method looks for the default viewer (probably xv). How do I change this (in the code, or in

Re: Some Issues on Tagging Text

2018-05-25 Thread subhabangalore
On Friday, May 25, 2018 at 3:59:57 AM UTC+5:30, Cameron Simpson wrote: > First up, thank you for a well described problem! Remarks inline below. > > On 24May2018 03:13, wrote: > >I have a text as, > > > >"Hawaii volcano generates toxic gas plume called laze PAHOA: The eruption of > >Kilauea volca

Re: List replication operator

2018-05-25 Thread Ben Bacarisse
Steven D'Aprano writes: > On Thu, 24 May 2018 16:05:32 -0700, Paul wrote: > >> How would one make a multi-dimensional list now, with truly-separate sub >> lists? Is there just no way to do it with the replication operator? > > Correct. Let's say you want to make a 1-D list with three items > in

Re: why do I get syntax error on if : break

2018-05-25 Thread bartc
On 25/05/2018 11:08, asa32s...@gmail.com wrote: On Thursday, May 24, 2018 at 10:12:46 PM UTC-4, asa3...@gmail.com wrote: here is the code, i keep getting an error, "break outside loop". if it is false just exit function def d(idx): if type(idx) != int: break d('k') thanks...

Re: Raw string statement (proposal)

2018-05-25 Thread bartc
On 25/05/2018 05:34, Mikhail V wrote: Proposal --- Current proposal suggests adding syntax for the "raw text" statement. This should enable the possibility to define text pieces in source code without the need for interpreted characters. Thereby it should solve the mentioned issues. Add

Re: why do I get syntax error on if : break

2018-05-25 Thread asa32sd23
On Thursday, May 24, 2018 at 10:12:46 PM UTC-4, asa3...@gmail.com wrote: > here is the code, i keep getting an error, "break outside loop". if it is > false just exit function > > > def d(idx): > if type(idx) != int: > break > > d('k') thanks... I believe the compiler. So how do I

Re: List replication operator

2018-05-25 Thread Serhiy Storchaka
25.05.18 10:28, Peter Otten пише: Steven D'Aprano wrote: But what do people think about proposing a new list replication with copy operator? [[]]**5 would return a new list consisting of five shallow copies of the inner list. Yet another arcanum to learn for beginners with little retur

Re: List replication operator

2018-05-25 Thread Chris Angelico
On Fri, May 25, 2018 at 5:50 PM, Stefan Behnel wrote: > Peter Otten schrieb am 25.05.2018 um 09:28: >> Steven D'Aprano wrote: >> >>> But what do people think about proposing a new list replication with copy >>> operator? >>> >>> [[]]**5 >>> >>> would return a new list consisting of five shallo

Re: List replication operator

2018-05-25 Thread Stefan Behnel
Peter Otten schrieb am 25.05.2018 um 09:28: > Steven D'Aprano wrote: > >> But what do people think about proposing a new list replication with copy >> operator? >> >> [[]]**5 >> >> would return a new list consisting of five shallow copies of the inner >> list. > > Yet another arcanum to learn

Re: List replication operator

2018-05-25 Thread Peter Otten
Steven D'Aprano wrote: > But what do people think about proposing a new list replication with copy > operator? > > [[]]**5 > > would return a new list consisting of five shallow copies of the inner > list. Yet another arcanum to learn for beginners with little return. If you cannot refrain