« first day (3198 days earlier)      last day (1753 days later) » 

Tim
3:00 PM
Using the black formatter will also filter out all the syntax error questions
 
wim
I don't like the way black puts those sad faces everywhere ):
 
@wim that's because happy faces would be a syntax error (:
 
Tim
You do get cake though
All done! ✨ 🍰 ✨
 
Question for Linux users: does subprocess.check_output(["ls"]) work, or do you need to do subprocess.check_output(["ls"], shell=True)?
I need shell=True if I want to call dir, but I'm guessing that's a Windowsism
 
former works
 
Tim
3:10 PM
ls is a program
 
I suspected as much, thanks
 
Tim
so shell=True is not required
 
Tim
Does anybody still publish sdists to pypi for pure python packages?
 
6
Q: Why can i read lines from file only one time?

krzyhubI have a file containing python's object as string, then i open it and doing things like i showing: >>> file = open('gods.txt') >>> file.readlines() ["{'brahman': 'impersonal', 'wishnu': 'personal, immortal', 'brahma': 'personal, mortal'}\n"] But then i have problem because there is no longer ...

 
3:14 PM
@X4748-IR yes?
 
Sais: "Your position in the file has moved"
How can I change the position to the first line?
 
Try file.seek(0).
 
second answer
 
I'm mildly annoyed that the accepted answer doesn't mention that. Seems like an oversight.
"Close the file, then open it again" is also a cromulent approach
 
@AndrasDeak ..... I didn't see that
 
3:15 PM
As is "read the entire file into a list of lines, and then you can iterate over that list as many times as you want" if you've got RAM to spare
 
@Kevin Thanks
I was wondering why my code doesn't work. It was because of the line position...! /:
 
@Kevin question is why the behaviour happens :P
 
I don't know what is the use of this feature. I mean line position
 
@AndrasDeak Yeah. But the answerer should have gazed into his crystal ball and determined that the follow-up question would be "... So how do I fix it?", and then he should have pre-emptively answered that question too.
 
@X4748-IR ugh
 
Tim
3:19 PM
@X4748-IR seek is byte offset, not line offset.
 
@X4748-IR Consider the following analogy: It is the 90s. You watch a movie on VCR, and later decide to watch it again. But when you play it a second time, the end credits are playing. "I would have preferred it to start from the beginning. Why would anyone want this feature?" you ask.
It's not so much a feature as it is a technical limitation. Certainly it's possible to provide an interface that always plays from the beginning, but this is difficult and expensive.
 
@Kevin :)) But I think python is the only language that has this feature! I haven't seen such this thing in other languages like C++/C/PHP/etc
 
@X4748-IR lol
 
My memory is foggy, but I'm pretty sure C++ has the same seek() and tell() interface
 
seek and tell is a game we used to play in junior high
 
3:25 PM
really? I think it doesn't change line position every time that you read
 
though I was studying and using C++ a long time ago. Maybe I've forgotten about it
But about php, I'm sure :D
 
Honestly, I wouldn't mind if iter(file) automatically made the file seek back to zero. But that's not the world we live in, so ¯\_(ツ)_/¯
 
I'll try again: PHP iterators
 
Tim
php has fseek and ftell
 
3:29 PM
No it deosnt!
 
@Tim That's right. I meant it doesn't go to that last line every time
 
Neither does python
 
Python's file.read() doesn't go to the last line either (if you supply an argument). Nor does for line in file: if you break early.
 
Python silly
 
@roganjosh Forget what I said ... lol
 
3:30 PM
readlines() goes to the last line because where else would it go after you've read the complete contents of the file?
 
It seems only readlines does that
 
Tim
They all move the file pointer as data is read, C/C++, PHP and Python
 
:46811296....! I Didn't know that...! It's been maybe two years I'm using PHP
 
I suspect the read/tell/seek interface is widespread because that's how you access files at the OS system call level
 
have to try...
 
3:33 PM
not resetting the file pointer is very useful if you seek/fast-forward to a start position
*then* do the actual processing
 
@MisterMiyagi +1
 
Tim
When you have large files it's required. You can't parse 80GB files into RAM.
Especially in Python...
 
I think skimming that PHP article has pretty much doubled my understanding of the language. The returns on 2 minutes reading are exceptional when you start from basically nothing :)
 
Going from 0 knowledge to more than 0 knowledge is an infinity percent increase in knowledge
 
Hi guys..
 
3:39 PM
"asked 1 hour ago"
 
If anyone knows please help.. thanks !
 
"Basically zero" is not zero, though. And the net understanding is still dismally low, so let's not get ahead of ourselves :P
 
@GeekDroid wait two days please
 
I guess you only need to know "There is a programming language named PHP" to have more than zero knowledge.
 
@AndrasDeak Ok any reason to wait 2 days ? Rules of this chatroom ? Or something else..?
 
@GeekDroid Try what Willem suggested in the comments.
 
> Don't ask for answers to your recent Stack Overflow questions. Those who can answer are already watching the queue on the main site.
 
@Kevin :D
 
Oh ok no problem....Yeah I asked him a question waiting for his reply..
 
Attempt to reduce fragmentation of information
 
3:42 PM
Really, as long as PHP exists in your personal light cone, then it's hard to claim that you have exactly zero knowledge of it.
 
@Kevin You should take a look at its frameworks. They're awesome. So easy to do what you want
 
Even unborn babies are influenced by PHP, in a chaos butterfly sort of way
 
PHP AFAIK is used only for small non enterprise projects ?
 
I've tried PHP. Didn't care for it. It's much more useful to me as a target of derision (whether it deserves it or not)
 
Tim
I've been doing my best to forget PHP...
 
3:44 PM
Throwing stones at PHP is a crucial community bonding experience
 
If PHP code answers a request on a server hosted in Brazil, does it cause a DDoS in China?
 
Tim
@roganjosh yes, if the developer copied and pasted the email code from the PHP docs :p
The good old "fake@email.com\nBCC: ${SPAMLIST}" attack.
 
@Kevin It's not that bad. It's designed for web developments, and there, it performs well.
 
I think its reputation has become overblown, but hey. I gotta put something in the wicker man to ensure a good harvest.
 
@Tim Fortunately no one is using raw PHP nowadays, Everyone is using frameworks. But it had many major bugs at the past
My friends were hacking many PHP websites per day... lol
 
Tim
3:53 PM
That answers your question. I'll stick to my Python thanks
 
wim
oh, you work for Westpac
please tell me why they limit your password length to six characters. it's ridiculous.
 
Tim
No idea
There are 30k+ employees
 
wim
Australian banks are a joke
 
Tim
I asked somebody in the Security Group
They didn't really know either
 
@wim Easy to remember! lol
 
wim
4:00 PM
they must store password in plaintext, otherwise they would not care the length
 
Tim
They don't
 
wim
hmm? well if they are salting and hashing then they have no reason to limit to 6 chars right?
 
Long passwords are harder to remember, so users might write them down, and hackers might break into their house and steal the post-it note that contains their password. Therefore, by requiring short passwords, the users are protected.
 
Tim
It's more to do with those silly onscreen keyboards
 
wim
oh yeah, that's another thing
stupid security theatre
 
Tim
4:01 PM
that are apparently more secure than my 40something char password in a password manager
and don't get me started about text messages for MFA
 
wim
they ditched the onscreen keyboard already though
 
Tim
I'm not involved in that team
 
(26*2 + 10)^6
(26*2)^n... hmmm...
 
Tim
I work in a team that stores and processes highly sensative data. Is frustrating that the account access is so simple, compared to what we do.
Thing is though, there is insurance on getting hacked and money removed.
The NOC (Network Operations Centre) do actively monitor login activity.
 
4:22 PM
Ah, the old "we know it's designed badly but doing it right is actually less cost-effective"
Sometimes it be like that
 
Tim
System I work on is underwritten by the banks balance sheet.
 
@DeveshKumarSingh the if accounts for the difference here stackoverflow.com/questions/57116346/…
+=10 vs +=9
Unless += and -= are inconsistent the two should be the same I think
 
4:38 PM
It's gone now, but that wasn't the worst "which of these is a nanosecond faster?" question I've ever seen. I think half of the downvotes came from people who didn't notice that the arithmetic works out the same in both code blocks.
 
it is kind of pointless with a constant condition
 
I think we can charitably assume that it was supposed to be variable
 
I usually think the same until I repeat a benchmark with pypy
sneaky little JIT...
 
I expect both approaches to be the same speed when the condition is False. When the condition is True, the if-else approach performs one fewer arithmetic operation than the just-if approach, but the if-else approach also performs one additional unconditional jump.
 
@Kevin check the first revision stackoverflow.com/revisions/57116346/1
 
4:44 PM
The first revision is a bit on the terse side but the math is still ok... Right?
 
yes
but "pointless question about two ugly-as-yam lines of code" gathers more downvotes than "pointless question about a well-formatted block of MCVE"
 
Based on no evidence, I expect JUMP_FORWARD to be faster than INPLACE_SUBTRACT, so I expect the if-else approach to be faster. This concludes my analysis of a pointless optimization.
 
@AndrasDeak Just saw that another edit was made right after I made that comment
 
@AndrasDeak Ok, the other half of the downvotes came from people who didn't like the ugly non-MCVE in the first revision
Lousy code blocks merit a score of -4, but we should reserve a score of -8 for a question with a flat out nonsensical premise
 
5:13 PM
@DeveshKumarSingh the edit doesn't change the validity of the code, it's just cosmetic
@Kevin I sort of agree, but I believe questions don't have "an ideal score"
 
In real life they don't, but in my fantasy world where everyone must follow my every whim, they do
I'll be honest. Not all of my whims would actually improve things if they were implemented in reality. This might be one of them.
 
5:36 PM
any ideas about CSS formatting in python? any good read?
 
@anky_91 what do you mean?
 
If you're asking "If I have a console program, can I style its output using CSS rules?", I don't think so. If you're asking "If I have a django project, how should I integrate CSS into my pages?", I expect it would be quite similar to providing CSS for a static html page.
 
there is something as styler , here object in pandas which is throwing a CSS warning in my code, thought you guys would know better. I am coloring some rows here :)
 
@anky_91 an mcve would be helpful (-:
 
Today I am exclusively working on problems with one-file MCVEs, so I don't have anything to contribute at this time. Let me know if you put one together.
 
5:40 PM
@Kevin I think that is quite close. although I am not confident enough in html
 
Never used it and I'm embroiled on the front-end as we speak. Personally, I would get the data out of the df and use dataTables
 
oooh!
 
Pandas just overstretches the mark a lot of times, and I'd rather have a front-end library handling the layout, not styles being passed out of the backend. But, I'll stress again that this is a personal thing, and I don't have the breath of knowledge to be definitive
 
@piRSquared sure, let me try that. 2 mins
@roganjosh no problem :) you are always appreciated
    data={'Name':['Ankan','Shiv',np.nan,'Sandeep'],
 'email':['ankan@domain.com','shiv.com','something@someting.com','sandeep@domain.com'],
  'Street 1':['Street Name 1','Street name 2','Street name 3',np.nan],
  'LastName':[np.nan,np.nan,'LastName1','LastName2'],
     'Outlet_Code':['123abc',np.nan,'12345','bca12']}
df = pd.DataFrame(data)
My data
this is the bool mask
    s=pd.DataFrame({'Name': {0: False, 1: False, 2: True, 3: False},
 'email': {0: False, 1: True, 2: False, 3: False},
 'Street 1': {0: False, 1: False, 2: False, 3: True},
 'LastName': {0: True, 1: True, 2: False, 3: False},
 'Outlet_Code': {0: False, 1: True, 2: True, 3: False}})
this is my func
def color(x):
    c='background-color: red'
    df1=df.mask(s,c)
    return df1
this is the code working
df.style.apply(color,axis=None)
 
This isn't the best possible way to present an MCVE. I don't want to have to copy-paste four different messages. Just put it all in one pastebin.
 
5:48 PM
the prob is when you do a .to_excel() it throws a CSS warning
 
And fix the two IndentationErrors and the ImportError while you're at it
 
@Kevin I agree, i just somehow cant access pastebin
 
df.style.apply(color, axis=None)
 
@piRSquared yeah this works, the .to_excel() doesnt without CSS warning
 
At the very least don't intersperse your code with non-code messages that I have to cut out
 
5:50 PM
@Kevin yesterday was a rough day, eh? Part of me is kinda glad I walked away from the no-MCVE questions when I did, but you battling on seems to have taken its toll :/
 
ok... anything to do with excel and i head for the door
 
:D
common
 
@anky_91 That's fine, any alternative text hosting site is OK
 
Excel, last I really used it, had nothing to do with CSS
Unless conditional formatting was converted to CSS. I actually don't know that. Maybe some web-magic was happening with my spreadsheet
 
I understand that. :D , i dont want to write a code with ignore warnings. I know the room rules are you can't share a question when it's not answered in 48 hrs(the reason why I didnt share it). May be I will share it when 48 hrs are over. but that was the full MCVE. did you find any problem replicating it @Kevin
?
 
5:55 PM
My search about formatting Excel having anything to do with CSS is not turning up anything I can see
 
@anky_91 It's not an MCVE. It crashes with IndentationError: unexpected indent on the first line. If I fix that, it crashes with NameError: name 'np' is not defined on the first line. If I fix that, it crashes with NameError: name 'pd' is not defined on the second line.
 
@Kevin got it 1 min I should for that for you
here we go
import pandas as pd
import numpy as np
data={'Name':['Ankan','Shiv',np.nan,'Sandeep'],
 'email':['ankan@domain.com','shiv.com','something@someting.com','sandeep@domain.com'],
  'Street 1':['Street Name 1','Street name 2','Street name 3',np.nan],
  'LastName':[np.nan,np.nan,'LastName1','LastName2'],
     'Outlet_Code':['123abc',np.nan,'12345','bca12']}
df = pd.DataFrame(data)
#-------------------------------------------------------
s=pd.DataFrame({'Name': {0: False, 1: False, 2: True, 3: False},
this works
but id you replace the last line with
df.style.apply(color,axis=None).to_excel(r'yourpath\file.xlsx')
you will face a CSS warning
that is what this question is about
 
@anky_91 I tried to run it using pycharm, but an image comes and goes away
 
@DeveshKumarSingh I dont use pycharm, but I think it best works with jupyter notebook
you can try to export this to excel
 
well what if someone doesn't have jupyter? MVCE should be able to run via an IDE or using terminal python <script_name>.py in my opinion
 
6:05 PM
I'm running it in a regular command prompt and it prints a CSS warning.
 
hmm, doesn't print anything for me when I run it using python3.7
 
Here it is, for reference. pastebin.com/cwpphRLA
 
I need one suggetion, I have text data and using description column I want to label that description to one name
how can I proceed
any lead please
 
@Kevin aah, I am running in on OSX, with pandas '0.24.1'
 
I'm no pandas expert but I reckon every time it complains about expected a colon in 'Ankan', what it means is "I expected some kind of styling rule such as "background-color: red" but you gave me some guy's name instead"
 
6:08 PM
It runs without error for me on Windows, Python 3.7, pandas 0.24.2
Both within and outside of Spyder
 
@Kevin thanks for that :) @DeveshKumarSingh i am not in control here :P jupyter does show the styling property best :)
 
I have a strong suspicion that the color function is poorly designed, because it has a parameter x that you never use
 
@roganjosh what if you do
import warnings
warnings.simplefilter('always')
does it still doesnt throw a warning
?
 
no warning for me
 
It throws a warning: "the imp module is deprecated in favour of importlib; ..."
But nothing about your code
 
6:12 PM
okay :( @DeveshKumarSingh @roganjosh i think i cant replicate for some sys then
 
I suspect color is not supposed to return an entire 4x5 dataframe. I suspect it is supposed to return a list of strings representing the style of each cell in the current column.
 
@Kevin yeah cant find anything in search too :(
 
@Taylor I don't understand your question. Where is there a "column"? Please give an MCVE
 
@Kevin In my case it should color the dataframe when the condition is met
 
Or, hmm, I'm seeing a discrepancy in between the documentation at pandas.pydata.org/pandas-docs/stable/user_guide/style.html and the output I'm getting.
 
6:14 PM
and it works fine in jupyter
 
Wait a minute
Jupyter is web-based, isn't it?
 
It says "we’ll turn to .apply which operates columnwise" which leads me to believe that the callable you pass to apply will be called with individual columns, but when I print x inside color, I see the entire dataframe.
 
it's when I am exporting this styler object that i am facing this
@roganjosh yes
 
So this error is probably specific to how the DF is supposed to be displayed within the notebook
 
@roganjosh In data set that "description" column is there using this column want to label the problem
 
6:15 PM
We're not going to be able to recreate the issue without Jupyter itself because it's how it's supposed to be displayed in the notebook. That's the issue.
 
@Kevin that is why i pass axis=None which does the apply() to the whole dataframe
 
If it's not clear, I was able to recreate the issue using regular old Python, so this issue is not exclusive to Jupyter. I wouldn't be helping if I couldn't.
@anky_91 Oh, I missed that. Ok then.
 
@Taylor That isn't a data set. Please actually read what an MCVE is. I think you're talking about Pandas but we have absolutely no way to be sure
 
Ok so basically your color method is returning a dataframe that looks like this:
0                  Ankan        ankan@domain.com          Street Name 1  background-color: red                 123abc
1                   Shiv   background-color: red          Street name 2  background-color: red  background-color: red
2  background-color: red  something@someting.com          Street name 3              LastName1  background-color: red
3                Sandeep      sandeep@domain.com  background-color: red              LastName2                  bca12
I expect this is incorrect. The cells that aren't red shouldn't contain "Ankan" and "Shiv" etc. They should contain empty strings.
Is there a version of dataframe.mask that lets you replace all cells with two different values based on a conditional? That would be useful.
 
those columns are way messed up
 
6:18 PM
@Kevin yes,exactly thats for test,when you pass this under styler, it would color the cells when you pass a mask()
 
@Kevin I've seen pandas people use numpy.where extensively, but I don't know if theres a pandaser solution
 
@AndrasDeak which one?
 
Pie
@PM2Ring Thanks for help. I download a compressed file of a few gigs. it extracted into two folders, which in turn extracted into two folders. I do understand how to use this resource.
 
here the doc for df.mask
 
@anky_91 All of them? :P I didn't read the original problem so I'm not necessarily right, it just looks way off with this mishmash of contents in each column
I think I understand what Kevin is saying and I'm not adding anything
 
6:21 PM
The addition I'm hoping you'll make is "oh, you want dataframe.ternary(cond, value_if_true, value_if_false)"
I don't think where by itself accomplishes that
Or, to be more precise, I don't think dataframe.where accomplishes that. numpy.where might be more powerful.
 
hmm. no worries. :) I have provided an MCVE to create the dataframe. It's just strange and an unknown territory for me. :)
@Kevin df.where() and np.where() are opposite
that is the reason I used mask() which is similar to np.where()
 
I'm way in the weeds at this point. I'm 99% sure your problem can be solved if you can construct a dataframe that contains only "background-color: red" or the empty string in each cell.
I'm sure there are a hundred ways to accomplish that; sadly I am unqualified to identify any of them.
 
@Kevin Great idea. let me try that with empty string. Than I will replace that
Will keep you posted :)
 
If you interpreted my advice as "try changing your code so it's c = "" instead of c='background-color: red'", I don't expect that to fix anything. Your style dataframe will still have "Ankan" in it.
 
i interpreted as c1='background-color: red' and c2=''
then np.where() in the func
not sure if I got that
 
6:32 PM
Ok, that makes more sense. I don't think that will work by itself because I tried df1 = pd.DataFrame(np.where(s, c, "")) in the color function and got a ValueError complaining about column names, but maybe there's an easy fix for that.
 
In [19]: pd.DataFrame(np.where(s, 'background-color: red', ''))
Out[19]:
                       0                      1                      2                      3                      4
0                                                                       background-color: red
1                         background-color: red                         background-color: red  background-color: red
2  background-color: red                                                                       background-color: red
I suspect mutating a df rather than creating a new one works equally well
 
^that's the dataframe I got. But it failed because the indices are 0 through 4 instead of Name through Outlet_Code.
 
ah
In [22]: df2 = df.copy()
    ...: df2[:] = np.where(s, 'background-color: red', '')

In [23]: df2
Out[23]:
                    Name                  email               Street 1               LastName            Outlet_Code
0                                                                       background-color: red
1                         background-color: red                         background-color: red  background-color: red
2  background-color: red                                                                       background-color: red
still not idiomatic though
 
Zooming out a little bit, I'm not sure why we're calling methods on df inside color to begin with, since ultimately the styling of each cell has nothing to do with the contents of the cells in df. We should be able to construct the style dataframe from s by itself, right?
Maybe it would be easier to just construct s in the first place so it has "" or "background-color: red" as values instead of True and False
 
yes, if you test with a boolean mask, the condition is easy to replace, the challenge is when we export tat to excel
@Kevin I am executing a lot of conditions on my dataframe based on which I am trying to color
the rows which meets the condition
i am starting to guess this is poor implementation
:/
 
i solved a similar problem here almost similar logic, but it didnt throw me that warning :/
 
Here's an approach which uses a Python-level loop and therefore is probably one million times slower than whatever the "right" approach is
def color(col):
    return ["background-color: red" if s[col.name][i] else "" for i, val in enumerate(col)]

df.style.apply(color).to_excel(r'file.xlsx')
 
hey guys, is there a clean way to represent the cyclic logic of 3 elements ala rock paper scissor
 
@Skyler define "logic"
 
The "right" approach is the one that works, and even if there's a trick to get Pandas to do it, it wouldn't surprise me if it's just loopy in its implementation anyway; how can it be vectorized?
 
6:47 PM
@Kevin wow.. tried that and it works. but i want your help in your free time to understand why a pandaic mthod didnt work :/
 
for instance you can use a dict to represent what a given element is susceptible to
 
No errors, produces desired output, only one million times slower than optimal... That's what I call "Friday-quality code"
 
Cyclicness doesn't seem very practical. itertools.cycle comes to mind, but you typically want to look up things by element rather than by index.
 
like this reminds me of a cyclic group from group theory. I know from a if statement the representation is pretty trivial
 
:D
 
6:49 PM
@Skyler I'm not following
 
@Kevin list comprehensions are almost always faster than .str methods of Pandas. You're potentially benchmarking yourself against boilerplate code
 
i am on weed now witout it
 
@anky_91 Your original approach didn't work because "Ankan" is not a valid style string. The dataframe returned by color should not contain any values from your original dataframe.
 
@Skyler You can also use a deque which you .rotate n times if you want. It all depends on what you're trying to do.
There's no "Logic" (with capital l) to a vague programming problem.
there are algorithms or tasks
 
@Kevin ohh okay.. wonder why it then returns a colored output when executing the code on the IDE
 
6:52 PM
The code you used at stackoverflow.com/a/57117141/953482 works because none of the original data from df is present in df1. Sure, you refer to the original dataframe in your replace call, but once notna() finishes executing, all that's left are booleans.
 
aha..... great insight sir. :)
but wait I am again confused
let me take a read once again
 
@anky_91 Although Ankan is not a valid style string, it's only a warning, and not an error. So the code continues to execute, allowing "Ankan" to stay in the style dataframe even though it doesn't make much sense. The bad style data is presumably still present in the xlsx file. But excel politely ignores the bad style and applies only the good "background-color: red" style.
Likewise for Jupyter and whatever other software you can export styled dataframes to. It is written: be liberal in what you accept from others.
 
@Kevin is it a good idea though? considering my stakeholder is going to drop input files and expects colored file?
I can ignore them
if it is
 
It's safe to leave the bad styles in if you're 100% sure that no data cell will ever contain a string that just happens to be a valid CSS rule. If a cell might contain something like "background-color: blue", then the cell may be incorrectly blue-colored when run through your program and viewed in excel.
 
Plus isn't it awkward if someone notices all that data where it shouldn't be?
 
6:59 PM
If you use my approach from chat.stackoverflow.com/transcript/message/46813388#46813388, you don't need to worry about that.
 
like, Sandeep's social security number in the font size field
 
Good point. It might be a security issue to copy data into invisible metadata fields. Makes sanitizing the document harder down the line.
 
@Kevin it wouldnt be 100% sure
 
Better use an approach that doesn't jumble up data and styling, then
 
i kinda didnt understand. so when I use mask() the condition which suffices gets colored. but the if else condition also does that> no?
 
7:03 PM
mask only replaces half of the cells in the dataframe, leaving the other cells unchanged. My list comprehension replaces all of the cells with either "background-color: red" or the empty string.
 
okay, only booleans
got it
 
So like someone said their solution to this 3 way problem is something like as follows:
"represent Rock, Paper and Scissors as 0, 1 and 2 mod 3, respectively. Then if a-b=1, a wins; if a-b=2, b wins, and otherwise there's obviosly a tie."
 
Hmm, it might be a fun exercise to create three objects rock, paper, and scissors, that each implement lt/gt so that rock > scissors, and scissors > paper, and paper > rock. I wonder how you could do that concisely...
 
With a dict: I_win = {('rock', 'scissors'): True, ...}
 
it could be one class with 3 instances, each with a value, and you can use self.value - other.value % 3 or something like that
 
7:14 PM
i must admit i dislike a math based solution to this, even if it may work it doesn't seem intuitive.
 
Half-serious solution: pastebin.com/aMYNBrXM
 
I think just have a bunch of if-else which makes it more intuitive
 
yea, that's why I was trying to see if there is some natural frame to think about this problem in
 
@ParitoshSingh on the one hand, yes. On the other hand: code duplication is ugly and error-prone.
 
like it'd be easy to write a binary logic game with the rules as follows: both players cant see the other persons choice, and they pick 1 or 0. If both pick the same choice the person who picked first wins. If they pick different results the player who picked second wins.
 
7:17 PM
just an input using pandas(might be overkill)
s=pd.Series(pd.Categorical(l,l,ordered=True))
dict(zip(s,s.cat.codes))
{'Rock': 0, 'Paper': 1, 'Scissors': 2}
 
but it seems like the 3 component nontransitive logic is a bit less natural a representation
 
if that is what you want
 
hmm
 
@anky_91 If your technique to produce {'Rock': 0, 'Paper': 1, 'Scissors': 2} is twice as long as just typing out {'Rock': 0, 'Paper': 1, 'Scissors': 2}, it's probably overkill ;-)
 
i didnt have a good vision about that. l=['Rock', 'Paper','Scissors'] , if you take a unique of that, it would sort the list and you could pass on to the second parameter in pd.categorical and ordered=True gives you the correct sorting too. But yes again depends. you are right
 
7:23 PM
The ordering is irrelevant
The game outcome cannot be determined by ordering alone
 
I think a modulus-based solution is relatively intuitive, if you visualize modular arithmetic as taking place on a number line bent into a circle
 
i get it now.. :)
 
Actuually, I think I'm talking nonsense again. Time to look at something not mentally taxing
 
like the roof above your head :P
 
Although I'm inclined to define the "a beats b" relation in terms of addition by a constant rather than subtraction by a variable... if a+1 = b, then a wins
 
7:39 PM
Can someone assist me with a specific Python code?
 
@Skyler You can do this with subtraction mod 3. Eg, let 0=paper, 1=scissors, 2=rock. Then if a and b are the values for the 2 players let r = (a - b) % 3. If r==0, it's a tie; if r==1, a wins; if r==2, b wins.
 
@g3lo If it's the same problem as the one at stackoverflow.com/questions/57118512/…, we like for users to wait a day or two before soliciting help for posts on the main site.
 
No its a different one.
-1
Q: Web scraping in python using BeautifulSoup - how to transpose results?

g3loI built the code below and am having issues of how to transpose the results. Effectively I am looking for the following result: Column headers: company name, Work/Life Balance, Salary/Benefits, Job Security/Advancement, Management, Culture Row 1: 3M, 3.8, 3.9, 3.5, 3.6, 3.8 Currently what ...

Having issues with something specific and unsure how to articulate it, hence the downvotes?
 
Incidentally, if the question you asked in that post is solved, you should mark as accepted the answer that suggested using .T. It's impolite to ask a second follow-up question in the comments.
 
I dont know how to move to solved if it was only a comment, the user didnt submit an answer. How do I tag solved for a comment?
 
7:43 PM
You can't. I was under the impression that stackoverflow.com/a/57118557/953482 is what you were referring to when you wrote that .T worked.
 
No
However, I did upvote the user
 
Ok, in that case you don't have to do anything. (this is why I very much dislike when people propose solutions in comments, incidentally)
 
Yeah
Any chance you can assist me with python related to my downvoted quesiton?
 
Ok. I'll post my thoughts in a comment on the post.
 
Many thanks
 
7:47 PM
perhaps better format the data you are trying to present with columns and rows, and don't worry too much about downvotes. If the question gets answered, that should be enough
 
I was just about to ask a long drawn out question only to realize that functools.partial was my answer. Thanks room 6
what should we do with all the csv questions tagged pandas? ¯\_(ツ)_/¯
 
as in?
 
Lot of questions mention dataframe, or have a df.xyz operation in the question, I retag them with pandas
should I avoid doing that?
 
I think doing that is fine.
 
7:52 PM
if its python thats fine @DeveshKumarSingh
 
The question then go away from my list since I have pandas in my ignored tags :)
 
@piRSquared do you mean that is not specific to pandas?
 
Hello all, I am doing a little cleanup for the [openpyxl] tag and I could use some help closing two duplicates. I apologize if this is not what this room is for, the room rules told me to ask for forgiveness, not permission :-)
 
@DeveshKumarSingh Thank you. Still looking for some help.
 
@DeveshKumarSingh watch out, there are also dask dataframes, and probably others
but vast majority is probably pandas on the main page
 
7:55 PM
@DeveshKumarSingh if the question doesnt necessarily need pandas, feel free to add a sol and remove pandas, I have seen and removed lots of questions that is tagged in pandas but is essentially a vanilla python question
 
@MackM Asking for close votes on Python questions is indeed permissible.
 
@MackM FYI, you can always post these requests to chat.stackoverflow.com/rooms/41570/so-close-vote-reviewers but posting dupe questoins and targets related to python are perfectly reasonable
@AndrasDeak aah, didn't know that, will be more careful in future
 
wim
>>> d = {}
>>> d['k']: "foo"
>>> something(d)
"foo"
^ puzzle, how to implement the something
(disclaimer: I don't actually know answer, or if it is even possible)
 
@anky_91 yeah but a lot of times the question and the code is so convoluted that it's hard to decipher what the OP is asking, but will do that if possible
 
wim
introspection of source code is cheating
 
7:59 PM
@anky_91 I disagree. You can never know whether a suggested answer is valid in pandas. If the question is not tagged pandas then suggesting pandas answers is often bad form. But if OP is already using pandas then opportunities arise to use it.
 
@wim im confused, can't i just iterate and return the first value?
 

« first day (3198 days earlier)      last day (1753 days later) »