« first day (3172 days earlier)      last day (2001 days later) » 
00:00 - 20:0020:00 - 22:00

00:14
Can someone tell me how to get this to work in reverse?
    arr = 'test'
    for i in range(len(arr)):
        test = arr[:i + 1]
        print(str(test))
        time.sleep(1)
at the moment it would do
t
te
tes
test
I'd like the reverse to happen
test
tes
te
t
 
2 hours later…
01:52
you can make your for go backwards:
for i in range(len(arr), 0, -1):
or you could also use while
@IsmaelPadilla Thanks that worked perfectly!
 
3 hours later…
04:42
Did anyone take a look at coldspeed's profile, it says that he is taking a break from the python chatroom
04:57
hmm. just saw that
 
4 hours later…
09:28
@JBower side note: I wouldn't call something arr unless it's a string
09:44
@DeveshKumarSingh Thanks, I'll watch it today :+1:
voted
10:14
stackoverflow.com/questions/56722846/… From the way it's worded, looks to be a dupe
10:38
@JBower I meant "unless it's an array", sorry :D
10:51
@AndrasDeak I assumed it was a typo... or you were being misleadingly sarcastic. :)
nah, just too early in the day :P
@JBower BTW, there's no need to do str(test), since test is already a string.
also print(...) will always implicitly call str
That too.
@DeveshKumarSingh It's definitely a dupe.
Hey @cs95 Don't be a stranger. Your contributions to this room are appreciated.
11:20
hey everyone i am new here , can anyone tell me how this works
thanks..
@its_vinayak Welcome to the Python room, the best chatroom on SO. :D
For the first time in my life I gave money to a musician playing in an underpass this week. He was playing The Force Theme on his violin. And well :)
11:44
@PM2Ring thanks ☺
 
2 hours later…
13:41
& @PM2Ring
Thanks, it was an array I'm working with on my actual project but for the example I used a string :)
@JBower Ok. It an array.array, or a Numpy array? Or did you mean it's a list? ;)
Please don't refer to lists as arrays. There are several array types in core Python: tuple, list, bytearray, and array.array, and the very popular Numpy library has arrays as well. Using the correct terminology reduces ambiguity, and makes it easier for people in the future doing searches. — PM 2Ring yesterday
14:09
for answering any question on SO, do we always need to find a possible dupe, and then if we can't find it, answer it
if i have seen a similar question before, i search for a dupe, else I reply to the question and again search for a dupe, if found , I delete my answer. Thats just my way of course :)
yes but not every time will you see a question for which you remember a dupe, okay you reply and look for a dupe again
the tag i answer in is pandas, and there are many redundant questions that I know is a dupe. Of course depends on that as well ;)
ohh okay, I just answer on the traditional python tag, which is more broad
Agreed, thats the reason I brought it up
Also there are some situations that might be related to multiple dupes combined together, but the OP is relatively new to both python and pandas, in that case i construct an answer
so that OP gets the required help
14:16
yes, an answer on a dupe is never harmful, in some cases
absolutely, depends on how much of reconstruction is going on based on that particular request. IMO
yep, thanks for the insight
My pleasure, would love other opinions too.
i have seen some profiles maintaining a list of dupes too. :)
@DeveshKumarSingh it typically is, that's why we want to close dupes
answers to dupes should go on the ultimate dupe target to prevent fragmentation of information
14:36
@DeveshKumarSingh These days, it's hard to write a good clear question that's not a dupe. So you should take a look for likely dupe targets. But if you can't find anything suitable in a few minutes, then go ahead & write an answer.
stackoverflow.com/questions/56724892/… Two dupes since two questions asked
okay, two slightly different opinions, but will keep in mind, thanks
If all the responsible & talented members spend half an hour fruitlessly searching for good dupe targets, then the rep-farmers and the kids posting low quality code-only answes will be the first ones to post, and score the upvotes. That's not fair, and it's not good for the site. So you need to use common sense to find the right balance.
added a python tag on the previous cv-pls request for the gold badge holders
The more time you spend on the site, the better you get at spotting likely dupes, and at finding good targets. It also helps a bit if you're somewhat familiar with our collection of Common Questions.
aah yes, forgot about these
user10984358
14:45
heya
user10984358
from IPython.display import Image
user10984358
I reckon that works only in notebooks?
user10984358
other than opencv or Matplotlib is there a way I can display images in a normal python IDE?
it worked for me in pycharm, I just tried it
user10984358
ohh, it didn't for me
user10984358
14:47
I had a file named image.py -_-
user10984358
my bad, sorry
see if the python interpreter in the pycharm is the same where you pip install ipython
@TheNamesAlc also PIL but why do you need a way without the tools that are made exactly for that?
well not exactly but still
user10984358
its for an assignment and I am pretty sure my college pc doesn't have those modules installed
user10984358
I thought a notebook might have those(Ipython) installed already
14:49
does the assignment say you cannot use those?
I don't get it, but OK
user10984358
@DeveshKumarSingh not like that, I do the assignment in my laptop but I have to demo that in a common PC at my class, and that PC has a bare bones python installation
user10984358
I wanted to know if there was any module other than opencv or Matplotlib that came as part of default python for the purpose of displaying images
@TheNamesAlc demo is not relevant right, if the assignment says the libraries are allowed, you can ask your college to get those modules installed
if they are not and you are using them, then that's wrong
user10984358
I honestly dont know what the others are doing, worst case I might have to save the images and do a slide lol
user10984358
14:52
but thanks for advice, I guess I will look into PIL
@DeveshKumarSingh Yeah, that's a slightly tricky case, since the OP really wants a dict comp, but his { N / freq[w] for w in freq } makes a set instead. In a situation like that, he needs an answer that explains the difference between the two. If an existing target for that can be found, then great. Otherwise, I'd hammer it with the dict comp target, and briefly explain the set comp thing in a comment, or even write a brief answer, if the OP seems like they're still pretty new to Python.
@PM2Ring it's hammered with dict, set and dict vs set answer
@DeveshKumarSingh Yeah, that works.
Another reason for dupe closing, connected to what Andras said about fragmentation:
Oct 25 '15 at 12:24, by PM 2Ring
We want all the answers to compete with each other for votes (and the magical green tick), we don't want all these separate pools of answers that don't get compared with each other. And we don't want future readers having to check a zillion pages to find the best answer to their question.
Unfortunately, there's a small problem with that approach. It can be hard for good new answers to compete with "dinosaur" answers that have huge scores but which promote outdated techniques. This can be a big issue for us, due to the Python 2 vs Python 3 thing.
I have a question, i know that {['a']} will throw an error since you cannot create a dict with a hashable list as a key, but how does cpython know we are creating a dict? We haven't even provided a value here, does it know from the {} syntax
That isn't a dict, it's a set
Well, in so far as broken syntax could be a data structure :)
15:03
okay then why does set(['a']) work and not {['a']}
I remember {} being used for dict, hence I assumed {['a']} for the same
There's a dupe for this. Give me a min.
set() takes an iterable so set(['a']) works, but I think {['a']} doesn't work but {*['a']} works
{} is a set literal display
@DeveshKumarSingh Because the set constructor accepts an iterable for its arg, but the set literal syntax expects a comma-separated sequence of items. And it can also handle * unpacking.
"Set" and "difference" are not making my search easy :/
15:07
@PM2Ring hmm, what I thought as well, yam I thought I remembered this :(
@roganjosh how about this one by Martjin
{("a", "b")} works, but it gives you a set containing a single tuple. ;)
It's an old Q/A with a lot of votes. It doesn't really matter now because you have seen the difference and I don't think it's going to give you any big revelations
Would this be the easiest way to get rows where the values are all the same? Or do we have a built in method for that? : df[df.diff(axis=1).fillna(0).eq(0).all(axis=1)]
@PM2Ring since it's hashable?
@DeveshKumarSingh Yes.
15:14
@PM2Ring and the big deal about set elements being hashable is because of the implementation right, hashing the objects make for the O(1) lookup in set and dict
@Erfan nunique() is one way, df[df.nunique(axis=1).eq(1)]
Yup, knew there would be an easier way. Thanks @anky_91
@DeveshKumarSingh Yes. They both use hash tables. So they keys have to be hashable. Semantically, a set is a dict with keys, but no values.
But not implementation-wise. They still aren't ordered.
You don't need to know how hash tables work to use Python. But it's a good idea to learn about them, at some stage.
15:18
@AndrasDeak yes, now they are not, but earlier they were before insertion ordering of dictionary
hello
@AndrasDeak Indeed. :)
I have 1 simple question
yes please go ahead
15:20
please anyone answer this:-
Unless you asked on SO main 10 minutes ago
class lector doesn't have a call method defined — Devesh Kumar Singh 8 mins ago
how edit code?
Ding ding ding
why does [::-1] reverses a string?
15:22
step=-1
click the edit button below the question
how edt code?
@Vicrobot slice(None, None, -1) might answer that
@TheNamesAlc You could probably use the standard webbrowser module.
@AndrasDeak Actually that's the source of doubt since neither start or end was specified.
15:23
how call class inside class?
@Vicrobot start defaults to 0 and end defaults to len(list)-1 if not specified
@Vicrobot hmm, yeah, I guess docs.python.org/3/library/functions.html#slice doesn't explain it
@DeveshKumarSingh no
@AndrasDeak only in case of list?
@DeveshKumarSingh can you please provide citation
15:26
[::-1] exactly corresponds to [len(lst)-1:-1:-1]. And [:] corresponds to [0:len(lst):1].
The exact behavior can be a bit weird at times
aah okay, and the behaviour is due to negative step,
At least to me, the negative step was the only part that made any sense when I first encountered it
@Vicrobot maybe this has a good overview, there might be better sources though
this might help
See table and its notes at docs.python.org/3/library/…
15:30
ha ha same source @DeveshKumarSingh :P
@AndrasDeak thanks, note 3 clarified it
No, this is note 5
sorry wanted to say note 5
15:48
Cbg
Cbg
@Erfan just a side note : df.eq(df.iloc[:, 0], axis=0).all(1) might have a better perf than df.nunique(axis=1).eq(1)
user10984358
16:34
c+=1 if e==p else w+=1
user10984358
how can I write a ternary if else where the else part uses a short hand assignment operator?
user10984358
is that not possible?
That's really confusing to read. Even if there is a way, i dont think you should use it
user10984358
so its better I write the traditional if then else ?
IMO, yes
user10984358
16:37
c+=1 if e==p else w+1
user10984358
can you explain why this works and not that?
user10984358
just outta curiosity
user10984358
its not what I want but its syntactically correct, that part aside I might like an explanation
Formally, no, actually, but it must be to do with the assignment in the first example
user10984358
well what confuses me is the += works peachy in the if part but fails in the else part O_0
user10984358
16:39
I guess I will just follow the normal convention then
w+1 can be evaluated without any assignment. But I certainly don't have the vocabulary to say exactly why this doesn't work
@TheNamesAlc ew, no
user10984358
lol
if it's an immutable object just use a proper if
user10984358
I caught on to this syntax from the list comprehensions
user10984358
16:40
its just an integer both c and w, initialized to zero before the loop
if it's mutable you can do lst = this if cond else that; lst.append(new_val)
@TheNamesAlc so drop it now :P
user10984358
alrighty
user10984358
thanks fellas
side-effects in a conditional expression are almost a bad as side-effects in a list comp
@TheNamesAlc right, but the statement already starts with an increment to c, not w
user10984358
16:42
I just assumed if it works with the 'if' it should work with the 'else' guess I was wrong
@TheNamesAlc But that increments c by w+1, and I don't think that's what you want to do.
user10984358
@PM2Ring is that what that does?? I thought it just stays 1 the whole time (w was set to 0) c just increments
@TheNamesAlc you parsed the statement incorrectly i think. c+=1 if e==p else 42 is actually parsed as c+= (1 if e==p else 42)
user10984358
59?
that's why it may seem like it's working on the if side, but no, it's not really.
i just chose a random number
16:46
I genuinely can't get my head around how you're reading that line of code so it's hard to understand how to explain
user10984358
that makes sense
there, changed it to 42. now everything should make sense :P
user10984358
what @ParitoshSingh said
user10984358
answer to everything 42!!
user10984358
while we are at this the whole purpose I did was to calculate the accuracy of a model
16:48
Is this what you're trying to do?
if e == p:
    c += 1
else:
    w += 1
user10984358
I read that clustering models dont have accuracy measures so I just found out the correct and wrong labels and multiplied by 100, is there a way I can evaluate the performance of clustering model?
user10984358
@PM2Ring yup
@TheNamesAlc Ok. There is a one-liner way to do something like that, but it's not good. You should just write it the way I did it.
@TheNamesAlc the whole point of clustering is that you don't really have "correct/wrong" labels in the first place. If you have a classification problem, why not build a classification model?
user10984358
yeah I might as well do that, I guess the one you are thinking of involves those ';' ?
user10984358
16:51
@ParitoshSingh I just omitted the last column, assignments demand I use the same dataset for both models -_-
and what is the "goal/task" of the assignment?
user10984358
is there any measure that deems the "correctness" of the model? like f score or any measures but pertaining to clustering?
user10984358
@ParitoshSingh train some models for a dataset and compare the effectiveness for the same dataset
user10984358
kmeans knn decision trees and such
FWIW, here's the one-liner way. Note that lots of people will hate you if you do stuff like this outside of code golf.
results = [0, 0]
for p in stuff:
    results[e==p] += 1
user10984358
16:54
that's cool in a messy way :p
Oh I didn't realise there were so many different options in python lol!
I'm not sure what type I'm using then in my actual project tbch. (though it's working absolutely fine so far luckily so it should hopefully be done correctly!)

If I was to try print it without converting to string etc it would shows as
arr = ['a','b','c']
etc
I've been under the influecne that that's an array (like an ordered map or keys/values)

What is the correct terminology for future references? Thanks :)
user10984358
alright I am gonna go continue with my assignment if anyone stumbles across my off topic question related to "accuracy" of a clustering model do '@' me
@JBower that's a list. but if in doubt, use type(arr)
@ParitoshSingh Thanks! didn't know you could check type like that, that's useful!
17:23
@PM2Ring that's using the boolean indexing I think it's called, since False = 0 and True = 1
2 pandas answer for printing formatted text here :|
@DeveshKumarSingh Correct. I don't mind it, but some people don't like to use bools as integers. Especially when they're used as indices.
@PM2Ring got it, I was trying to recollect it :)
OTOH, doing stuff like sum(e==p for p in stuff) is a little more tolerable.
I guess the bool-as-int haters would prefer sum(1 for p in stuff if e==p) to my previous version
There should be a count function, honestly
:46577625 It gives the same result, but your code is still using a bool as an int, plus it has to do a functiin call on every iteration.
@Aran-Fey How do you feel about: sum(int(e==p) for p in stuff) ?
17:35
@Aran-Fey count how many e's are in stuff?
what about Counter(stuff)[e]
@PM2Ring Hmmm. Better than without the int, I suppose. I'm not a huge fan of it, but I have to admit if you write it like that it's actually pretty readable.
@DeveshKumarSingh you can probably think why that isn't what Aran would be looking for. that requires making the counter first.
@DeveshKumarSingh Using a Counter is probably the fastest solution. Wastes some memory, but eh.
@DeveshKumarSingh It's a bit wasteful if we only want a count of the items in stuff that equal e
17:38
okay then what's the best way?
In [10]: counter = 0
In [11]: for p in stuff:
    ...:     if p == e:
    ...:         counter += 1
@PM2Ring wasteful in terms of space right, otherwise its O(n) and one pass, unlike sum(int(e==p) for p in stuff) which first generates all integers and then sums them, or it sums as it generates?
@DeveshKumarSingh Space. dicts have a fair bit of overhead, due to the hashtable. Even an empty dict is 320 bytes on a 32 bit machine.
Nobody pandas-genic here today? (FYI all you know koalas is coming to Spark, a drop-in replacement for Python pandas, right?)
Yes, sum can sum as the gen exp generates, it doesn't build a list.
@smci pandas is in my ignored tags. cs95 is taking a break from room 6.
FYI I'll do that slowly, as a non-priority project, and I'll be offline most of July. So, no promised date. But cs95 gave really helpful suggestions how I could do it.
@smci Yes, it does. It's been on my ignored tags list for about a year. But I still end up seeing yamming pandas questions because so many newbies don't tag their questions properly.
17:53
@piRSquared Neat, please post that on CodeReview.SE (or wherever most appropriate) so people can post entries and discuss.
@PM2Ring I hear ya, but if several others of us form the village cleanup militia, we might remove the monster from the pond and it could be safe to come back in future... the API/SEDE approach for super-common questions sounds good place to start.
(The enthusiasm is deafening... ;-) )
@smci Not CR, providing golfed code or asking to golf code is off-topic there.
@Peilonrayz Aw crap, where can we post pandas golf? (that is not an outright puzzle, so not Puzzling.SE?)
Unfortunately I only contribute to CR, so can't say anything about other sites.
The pandas tag is probably beyond redemption in terms of dupes. With the best will in the world, I don't think you can capture all the similar problems
Hi everyone
18:02
Add to that that one of the most active people in the community, who is without doubt very talented, still answers dupes regardless
That said, I don't think it's actually too bad on a case-by-case basis. If you had such a variety of approaches in pure Python, there'd be a real issue. In pandas it kinda works
@roganjosh I hear you, and the collective opinion here too. Since I am naive and foolhardy, let me a take a stab at it (per my suggestion) over the next few months, and let's see how that goes.
@roganjosh Right, the frustrating part is with pandas there are actually pretty good 'guardrails' towards code idiom that's most pandas-genic, short, legible and performant. (Obviously those change and evolve as pandas versions evolve). As opposed to say polymorphic messes like handling IP addresses
I read about 5th note of this
If you make headway and get real progress, then I will help out (if there's structure to the approach). I fear that the job is too big, but I don't wanna shoot down the intention before it's tested :)
@roganjosh Let us start Vulcan-drop-forge-hammering the most blatant and common dupes, then see how people's answering behavior evolves.
@roganjosh Jeez, I wonder who that could be...
18:10
@roganjosh Ok cool man, I appreciate. As said I will not have much bandwidth till mid-August, so I'll tinker with it occasionally and may pop by here for advice.
it tells that if i and j are none in slice notation, they take end values, depending on sign of k. But since they are on same index, shouldn't [::-1] return null string instead of reverse??
:) I'm sure you already know the user that won't change here
Yeah, I wasn't asking you to name names.
@Vicrobot That note also says: (which end depends on the sign of k)
It's actually a shame because they have some yam-hot insight
@smci how's the weather in the bay though, I was in MTV till April this year
18:14
@roganjosh fgitw behavior and answering dupes can be read as a sign of frustration and misplaced intentions... I view it as a symptom of messed-up incentives, not the root of things. Let us slowly clean up the incentives, remove the dupes, agree on our basic canonicals to close really simple askings like how to append, find duplicates, transform wide-to-long etc. Then when we physically remove the incentives, likely answering/closing behavior will change...
@PM2Ring Why does it iterate at all when both i and j are on same index in this example:- 'any string'[::-1] #which is providing reverse string here.
One of the highest rep members on Physics.SE is a chronic answerer of dupes. But she gets some leeway because she did her degree in particle physics half a century ago, and I think she worked on colliders at places like CERN.
@Vicrobot the meanings of "end" location changes based on the sign of k. as you can see, [::-1] or any negative step size would become pretty useless on its own if such behaviour was not coded in. would you rather have [::-1] return a None, or reverse? it iterates because it is written to iterate.
... If each of you wants to nominate your personal "Most annoying pandas question whose constant recurrence prompted me to mute the entire tag", I'll try to incorporate them. Pref ones that have universally defined pandas keywords that don't mutate/evolve. (Whereas, 'append', 'concatenate', 'add' and 'merge' are basic-sounding terms but actually context-varying, time-varying meanings...)
@Vicrobot i & j aren't both at the same index, though.
18:17
At least in my opinion, there would need to be a curated list of dupes. SOPython has one, but it's easier to see the dupes there. Pandas is more data-driven so I don't blame people for not being able to boil problems down to their roots
i nominate no mcve as my pet peeve for pandas.
also, hi smci. how are ya
@PM2Ring Aren't they both sitting at last value, or am i wrong somewhere?
by last value, i mean -1
a[::-1] is equal to a[len(a)-1:0:-1] which means start from the last element, and go to the first element by reducing the index by 1 everytime
@smci I don't ignore the pandas tag just because it's flooded with dupes & bad questions. I ignore it because it contains questions about Pandas. I don't know Pandas, and at this stage I have no interest in it.
@DeveshKumarSingh But what about not including 'j' rule?
18:21
@roganjosh Totally. Answers vary depending on whether the data is about a pandas DataFrame, Series, GroupBy, or numpy ndarray or other thing. Also the type of data (integer, float, numeric, boolean, categorical, string, other) Askers often omit those "essential basics", so maybe I'll need to develop something regex-tastic to figure it out. Also, we've no tags for such things, and even if we did, 5 tags is a small limit (when at least 2/3 of those will be Python(/version) and pandas(/version))
@ParitoshSingh Okay let's start the death-list. 1) Paritosh: "No MCVE"
@smci just curious, have you considered a cost-benefit analysis before you start this? For example, what exactly will work better from your effort?
The tag does actually go on regardless and people get answers. I don't like it, per se, but it is functioning
Re MCVE specifically for pandas, this was asked on SO instead of Meta, and closed in 2018. I don't understand why people didn't instantly advise "great, but migrate this to Meta". There is also this much more general, language/package-agnostic Meta question
Nobody seems to be able to get consensus on where it should be
@Vicrobot sorry my example was incorrect
I know, actually, it seems like [-1, len(s) -1: -1] but that shouldn't iterate then, and this is only possible slice i can think of for now. This seems like noggin eater.
18:35
hey guys, so if a[:] equals a[0:len(a):1] then what will a[::-1] be equal to?
@DeveshKumarSingh the middle index is wrong, I've already written it right
seriously
3 hours ago, by Andras Deak
[::-1] exactly corresponds to [len(lst)-1:-1:-1]. And [:] corresponds to [0:len(lst):1].
how can you still be stuck on this?
@AndrasDeak yes I realized that
5 mins ago, by Devesh Kumar Singh
@Vicrobot sorry my example was incorrect
@AndrasDeak So why is it iterating at all instead of returning a null string? (since index are same of i and j)
i and j are both None which is a special case
actually, I seem to be wrong here, hold on
yes that's what I realised too
In [67]: a
Out[67]: [1, 2, 3, 4]

In [68]: a[len(a)-1:-1:-1]
Out[68]: []
but
18:38
bah
In [69]: a[len(a)-1:None:-1]
Out[69]: [4, 3, 2, 1]
getting confused between range and slice, apparently
they aren't the same index.
> If i or j are omitted or None, they become “end” values (which end depends on the sign of k).
To be fair, it is a little confusing because of the way Python treats negative indices. What Andras wrote uses actual indices, not subject to the -1 -> len(a)-1 rule.
I think the second element is chosen as None to include the first element
otherwise we have
In [70]: a[len(a)-1:0:-1]
Out[70]: [4, 3, 2]
18:40
I'm getting more confused
-1 and len(a)-1 refer to the last element i think, hence the list is empty
ah, right, that's probably it
and if we do 0, it skips the first element, so we need to do None
So indeed what I had in mind works for range, where you just have ints. Negative indices mess with it.
wow, perhaps I am right the first time :D good that I was stuck :)
18:42
So while what I said there about the indices is technically true for positive indices but it is definitely not true for negative indices which was my intention. Sorry about that.
no worries :)
I'll guess I'll just stick to this in the future:
3 hours ago, by Andras Deak
The exact behavior can be a bit weird at times
yes you did have a disclaimer :)
so what's the conclusion? j = none?
the conclusion is that j = None means "until the start of the array if k is negative"
and "until the end of the array if k is positive"
and you can't replicate the former behaviour with any other kind of numeric j
18:44
^ this. what's amusing is, i dont think there's a single way to write it in python at all.
at least that's what I think now, who knows what'll happen an hour from now :/
is that explicitly coded?
In [75]: a[-1:-5:-1]
Out[75]: [4, 3, 2, 1]
@Vicrobot what do you mean? That's how slice is implemented, yes. And what I linked originally in the docs probably covers it, but I didn't read it in detail.
3 hours ago, by Andras Deak
See table and its notes at https://docs.python.org/3/library/stdtypes.html#common-sequence-operations
you saying no numeric j can replicate that, so what is that iteration targeting to?
18:53
@roganjosh Oh yeah, sure in part I want to answer my own questions. My two main angles are the intersection of a) good idiom (esp. where things change between versions) and b) performance-specific stuff. (We all know people can write O(N^2) appends and concats, but they're non-scaleable)....
@Vicrobot The "problem" is that the behaviour in note 3 forces us to use None for j in that situation.
3. If i or j is negative, the index is relative to the end of sequence s: len(s) + i or len(s) + j is substituted.
...Also, pandas is becoming trailing-edge and is/will continue to leak users to Spark, koalas, MLLib, and people are getting frustrated with the backend performance, hence dask. Ditto, sklearn. I do not want ML code in Python/pandas/sklearn to become synonymous with "low-performance non-scaleable cruft", like it's in severe danger of becoming... we must stamp out heresies and bad practices as they arise...
If you write -1 for j, Python will always convert it to len(a)-1, so you have to write None instead.
Most of the time, the note 3 behaviour is very handy, but occasionally it's annoying. One way around that is to use a forward slice, and then reverse it.
Eg, thing[i:j][::-1]
@Vicrobot Remember, implementation of the language is responsible for resolving how None works. Just because you cannot use -1 to mean "before start of list" in python, does not mean cpython cannot do it. infact, that's exactly what it uses
So yes, you cannot express [::-1] using a numeric j
unless you do a[-1:-(len(a)+1):-1] ? since -(len(a)+1) is the element before the first element?
19:00
Also consider the reversed function:
Return a reverse iterator. seq must be an object which has a __reversed__() method or supports the sequence protocol (the __len__() method and the __getitem__() method with integer arguments starting at 0).
@DeveshKumarSingh that's pretty amusing actually.
yes but makes sense right, -1 is last element and -(len(a)+1) is the element before the first element
well, no not really. it's something else at work here im afraid
try any number with a bigger magnitude and a negative sign.
but so is any number bigger then the length at j with positive step, if you specify a stop bigger than the list limits, it defaults to the last element
the values are being correctly clipped as needed, though it's amusing that in that sense, technically -(len(a) + 1) can be thought of as translating to a position before the 0th slice in a very roundabout way
19:04
which is I guess here ?
so i wouldn't call your observation wrong either
it is roundabout lol, the correct way is a[len(a)-1:None:-1]
@DeveshKumarSingh That rings a bell... :)
@DeveshKumarSingh Sometimes, it's not convenient to use None, because you're computing the start and stop indices inside some loop.
19:10
@DeveshKumarSingh flag as spam, it's beyond a close vote
and the code appears
As it happens, they've now posted code, but I've flagged it
@DeveshKumarSingh Well, I have messed around with this problem before. But it was a while ago. And I haven't actually done much coding at all in the last 6 months, so some of my Python knowledge is getting a little rusty.
@PM2Ring but then we use the bigger index which goes beyond the list limits right, atleast in positive step
@roganjosh Someone (possibly me) needs to get around to reasking the very specific "How to make good reproducible pandas examples/ MCVEs?) on Meta, incorporating and expanding the previous SO question, and referencing the general, language/package-agnostic Meta question...
19:15
We're gonna disagree about that :) I don't think it's worth the effort vs someone, possibly in the sky, deciding where the original should live
...Knowing the crowd on Meta, we will need to spell out why both Python and Pandas versions matter crucially (both for evolving features, performance, idiom) (and sometimes also the Windows/MacOS/Linux/etc version, or compiler version, or Anaconda version). Again this is something to write slowly and carefully and keep our powder dry until we have a good wording.
@roganjosh On Stack Exchange, spam means commercial spam, not gibberish. Posting actual commercial spam incurs heavy penalties. Don't use spam flags for stuff that isn't actual spam.
Is editing the code of an question to fix indendation allowed?
@smci I admire your optimism that people will read whatever you plan to write for them. As a rule those who should be reading a guide are typically not the people who end up reading it. In a more optimistic light, those who are prone to reading guides can already figure out their issues without having to ask on SO.
@DeveshKumarSingh rather not, because it can introduce or remove bugs
with the new code fence syntax it's less dangerous, but still
@roganjosh You may well be right: the alternative is we all decide to collectively give up, block pandas tag, and collectively author a Medium post "Why the SO tag is broken and why SO is structurally unsuited to fixing it - signed, the Python Community on SO". I think we're getting close to that crisis point but not quite there yet.
19:18
@AndrasDeak okay thanks
All it takes to fix SO is some improvements to google's search algorithm :P
@DeveshKumarSingh Generally not, because it may edit out the OP's problem. But if they posted code & simply didn't put it in a code block, it's ok to fix that.
@PM2Ring yes that I do, but now I acquired a bad habit now to put triple and single backticks to emphasize text too :(
@AndrasDeak No, you misunderstood me. That would be collectively agreeing tag-specific house-rules on pandas MCVE, what a pandas MCVE must/should contain, reasons for prompt closure of other people's posts. For example: my pet peeve is people who complain about performance, yet don't state both their Python+pandas versions, or just use O(N^2) non-vectorized crap like iterative-append/concat,df.iterrows, don't read the tutorial and try the apply function, etc.
@Aran-Fey It would help if Google didn't give such a high priority to the question titles. Trying to dupe hunt by using keywords from the body of the answer is almost impossible.
19:24
@PM2Ring fair enough
@smci I probably did
I read (somewhere) fairly recently that Google simplified their Stack Exchange search algorithm a little while ago because the average quality of the posts here has been reduced by the flood of dreck. But I don't know if that applies to the whole network, or just to the busy sites like SO, Mathematics & Physics.
@AndrasDeak aye aye sir!
IIRC, a successful spam flag results in a 100 point rep loss. Of course, most spammers only have 1 rep anyway.
19:29
@smci well, the alternative does necessitate blocking the tag. People like PM choose not to follow it. I don't filter for the tag specifically and I will help if I can.
@PM2Ring indeed.
if the pandas tag gets deleted, all hell will break loose
Wait, why would anyone delete that tag?
I edited. Oops :P
ah.
roganjosh, master of meta-terminology strikes again :P
19:31
No anarchy in my name,please :P
@AndrasDeak No, this is important. Everything I've said here on pandas tag is on the pragmatic assumption that a hardcode subset of (pandas) askers won't read or follow any SO guidelines), and will continue to post low-grade non-MCVE garbage. But if we agree house rules for instantly closing such stuff, they either have to follow the rules or leave. However it is the pandas community's responsibility to spell out (on Meta) what a pandas MCVE should contain. That at least seems achievable to me
Sometimes, spammers will post non-commercial gibberish, designed to get around spam filters, and then a few hours later edit it with the actual spam payload. If you suspect that to be the case, you can raise a custom flag, explaining that the post is a potential spam precursor, or words to that effect.
Basically, time's up for the 'givemetehpandascodez' brigade.
@smci we already have rules. The issue is not specific to . Look at and . Torrent of garbage with a torrent of lazy and farming and "just want to help" answerers.
the issue is the great divide between quality-control lunatics (such as myself) and helpdesk fanatics and rep farmers
(there's not a huge practical difference between "we're just here to help people" and "I need all teh points")
As far as official rules go we could close all the MCVE and other broad crap. Most of them are dupes anyway. The problem is that there aren't enough able and motivated crap shovelers and there are more than enough answerers-at-all-cost.
@AndrasDeak No, pandas needs very pandas-specific rules on the MCVE. Not just the general SO rules. Also self-evident stuff like "Don't write iterative appends/concats/.iterrows then start complaining you got bad performance - vectorize instead."
19:34
okay
Yes, the ratio of crap-posters to crap-shovelers has gotten out of hand and is near breaking-point. Also SO's broken structural assumptions that all pkgs are stable, not frequent version changes that break. On pandas 10-year-old questions, the highly-upvoted cream does not rise to the top, it curdles, becomes obsolete; yet both SO and Google search don't attach importance to version numbers hence they continue to misdirect people to ancient highly-upvoted, stale, broken, non-performance answers.
@AndrasDeak "In a more optimistic light, those who are prone to reading guides can already figure out their issues without having to ask on SO." Err, no, absolutely not, I'm a 10-year user of both Pandas and R. Pandas has had 24 major versions in 10 years, and Python has fragmented into 2.7/2.8, 3.4/3.5, 3.6 and 3.7 versions; 3.8beta is out now. fragmentation is known to be far worse in pandas or scientific users since they often have trailing or 2.x dependencies like PIL or Fortran or C cruft.
I've been reading pandas doc, tutorials, PyVideo, PyData, kaggle etc for years. Gives me a fulltime headache how so many users are struggling with such basic stuff and getting it wrong. SO is simply (not) currently structurally equipped to understand and handle very fast-changing packages with frequent breakage, deprecation, performance changes, idiom, and correspondingly invalidate/age/ignore/obsolete old questions and answers. Missing version numbers and massive fragmentation exacerbate that.
00:00 - 20:0020:00 - 22:00

« first day (3172 days earlier)      last day (2001 days later) »