« first day (2965 days earlier)      last day (1983 days later) » 

12:05 AM
Why I gotta install everything
import BeautifulSoup
I have to install that?
 
it's not in the standard library, so yes
 
I pip install beautifulsoup4 now how do I import into project?
 
Be happy... it's free
 
@W.Dodge Its a usual occurrence for python packages to cost $$?!
 
I'm sure the documentation will help you figure out how to import it
 
12:11 AM
hold on my IDE may come to resuce
yep
thanks
 
wim
$ johnnydep beautifulsoup4 --fields import_names
name            import_names
--------------  --------------
beautifulsoup4  bs4
^ my app johnnydep also got this feature
 
Noice!
 
12:27 AM
?
looks cool. How does it work?
 
wim
Python distributions packaged by wheel + setuptools/distutils usually has a file called top_level.txt where you can get this info.
 
12:46 AM
ah cool
 
 
2 hours later…
2:27 AM
Hey, check it out, my wife recorded a video in Ukraine with some amazingly beautiful videography
4
 
 
2 hours later…
4:52 AM
@AaronHall Sounds great!
 
5:23 AM
morning cbg!
 
6:05 AM
cbg
 
 
1 hour later…
7:11 AM
@wim no, but auto-modflag
 
 
3 hours later…
9:45 AM
cbg
If I delete pycache while a python script is running, can it cause errors?
 
 
1 hour later…
10:50 AM
@martinjn how it can be implemented in jononomo code? — Bimlesh Sharma 4 hours ago
What on earth is "jononomo code"?
Google seems to agree with that reaction.
 
not useful either xD
 
11:15 AM
@MartijnPieters jonomomo's code, the code from the thread-starter
 
@Arne ah, see, that's the kind of thing I hoped someone would point out to me. :-D
Totally missed that.
At which point that commenter is clearly not understanding that my answer already shows that. Sigh.
 
¯\_(ツ)_/¯ seems like it wasn't spoon-fed enough for their taste.
 
 
1 hour later…
12:58 PM
cbg
 
1:08 PM
hey guys
kinda stuck on parsing the data from a dict
{'data': [{'id': 921254176609314, 'gid': '921254176609314', 'name':
i need only the 'name'
any ideas ?
 
If anyone can comment on tag disambiguation/renaming between (parsers) and (C++/STL containers)? in this question on meta
 
@Andie31 can u paste the full dict key which you are trying to parse?
 
@Tyto sure
actually not :( message is too long :(
{'data': [{'id': 921254176609314, 'gid': '921254176609314', 'name': 'TW-11.23.18-[1]-Priority_Babolat_Racquet', 'notes': 'http://www.tennis-warehouse.com/zzz/producttracker.html?ccode=SWIMG23154\nhttp:‌​//www.tennis-warehouse.com/zzz/inviscatpage_views.html?ccode=SWIMG23154\n\nBabola‌​t Pure Drive VS 4 1/4" (#2) 499.00\nhttp://www.tennis-warehouse.com/descpage-PDVS2.html\n\n'}]}
 
@smci (sigh at the downvoter's comment...)
 
let's say your dictionary is x...now first if we parse through the key 'data' of x, let's say that gives us 'y'.
@Andie31
so your name value would be y[0]['name']
try this and let me know if it works...
 
1:34 PM
@Tyto I'm doing something like :
data = requests.get(http://example.com).json()
dict= data

for key in dict.keys():
print (key)
and the output is just : >> data
:(
and if I try your solution
I get print(data[0]['name'])
KeyError: 0
 
@Andie31 That link is not working for me, but you say you just want name from your initial example, right?
 
@W.Dodge correct (the links is too long to paste so I just changed it to example.com)
 
    >>> dict = {'data': [{'id': 921254176609314, 'gid': '921254176609314', 'name': 921254176609314}]}
>>> dict["data"]
[{'id': 921254176609314, 'gid': '921254176609314', 'name': 921254176609314}]
>>> [{'id': 921254176609314, 'gid': '921254176609314', 'name': 921254176609314}]
[{'id': 921254176609314, 'gid': '921254176609314', 'name': 921254176609314}]
>>> dict["data"][0]["name"]
921254176609314
>>> 921254176609314
That's a bit muddled but you'll notice that dict["data"][0]["name"] returns the value for name given your example
 
1:54 PM
@W.Dodge you are THE Man !!!
it works and I learned something new ! Love you guys !
last question - how do I loop through a list of 'name' ?
 
for i in dict["data"][0]["name"]:
    print(i)
Obviously this assumes the value for name is a list
 
@W.Dodge hmmm looks like it's not :(
it prints one character per line
 
Okay name is not a list, it is a string
Please clarify what you mean when you say "loop through a list of name"
 
Ohhh my bad I said list :(
well inside that dictionary I have multiple 'name' instances
I wanna get all of them not only one [0]
if that make sense
 
Make a minimal example of your nested dictionary. If less than ten lines you can post here, else use pastebin
 
2:11 PM
@W.Dodge here : pastebin.com/8TnZMPxy
there's 2 'name' instances in that list
 
for i in dict["data"]:
    print(i["name"])

TW-11.23.18-[1]-Priority_Babolat_Racquet
RW-ATL-11.26.18-[4]-Caps_Socks_Mix
 
@W.Dodge Thank you so much ! I gotta sit down and learn more about dictionaries ! Lesson learned ! Thank you so so much !
 
No problem
 
3:01 PM
cbg
 
cbg jc
 
how goes it?
 
aggravated with work task. So I look for a quick dopamine hit of answering a question. Nothing pandas worthy, so I don'd get my satisfaction.
 
Haha... hope you've not got the shakes because of it or something :)
 
Nothing so bad that 3 cups of coffee can't handle
 
4:05 PM
@Andie31 If you'll luk at my solution it's almost similar to what @W.Dodge has given. But it's more decoupled for your understanding, I guess...
But what @W.Dodge has given is more pythonic way,I must say...
 
@n8_ that is strange, if the number of items in the list and the number of rows in df are the same, then you shouldn't have problems assigning the list to df
 
n8_
@W.Dodge, so when I leave off the -1 and open the generated file, Excel says there was an issue with the formulas and asks to recover them. Then it says Excel removed the formulas, which are all zeros now
If I leave the -1, it says Must have equal len keys and value when setting with an iterable\
here is the full code
`# create list of formulas to insert into Meds column
length_of_df = len(df_final.index)
list_of_formulas = []

# loop to create list of formulas based on cell
for i in range(2,length_of_df+2):
formula = '=IF(COUNTIFS(Sheet2!A:A,E{0}>0,1,0)'.format(i)
list_of_formulas.append(formula)

# write list_of_formulas to the Meds column
df_final.loc[:, "Meds"] = list_of_formulas

# write to csv
df_final.to_excel(writer, sheet_name='Combined')
meds.to_excel(writer, sheet_name='Meds')

# Close the Pandas Excel writer and output the Excel file.
 
For future reference, please use pastebin for code in chat greater than ten lines or so.
 
n8_
Gotcha
 
Let me look at this a little more, I may have missed something in the way this writes to excel. I will update my answer and get back to you this afternoon.
 
n8_
4:17 PM
Tried to change length_of_formulas to length_of_df = len(df_final)
Thanks so much!
 
@W.Dodge or even better just a gist... no one really needs all those ads :)
 
Okay, makes sense
 
@MartijnPieters what on earth is martinjn?
 
Hi, I have stumbled upon the following problem when styling the dataframes. I am using .style.background_gradient('RdYlGn') and I need it applied column-wise (which is the default case). I have 5 ranks in each column, so integer values from 1 to 5. Sometimes a column will only contain 5's and 4s. And in such a case 5s get a green colour and 4s get a red colour... Has anyone stumbled on a problem like this? What is your solution?
 
4:35 PM
@isquared seems a reasonable result - perhaps a custom function that applies styling on the criteria you want?
 
@JonClements yh. I'll probably do a colour map for integer values. I also have averages, for those I will just use the default behaviour.
 
I've had similar before where I've wanted to highlight the min/max columns per row, but they're either all the same, so there is no real "min" or "max" value where there's joint min/max values etc... I just wrote a custom style function
 
@JonClements how would you make it behave as .background_gradient('RdYlGn') in exceptional cases inside of your custom styling function? (i.e. leave in the default behaviour for some columns)
 
apply the default, then apply the custom one on top is a naive way of doing it?
 
4:55 PM
@isquared-KeepitReal
df = pd.DataFrame(dict(A=[0, 1, 2, 3, 4, 5], B=[1, 1, 2, 2, 1, 2]))

def get_f(df):
    v = df.values
    mn, mx = v.min(), v.max()
    cmap = plt.get_cmap('RdYlGn')
    return lambda x: f'background: rgba{cmap((x - mn) / (mx - mn), bytes=True)}'

df.style.applymap(get_f(df))
RO, feel free to delete prior entry
 
5:20 PM
@piRSquared rSquared is in the house :)) Thanks!!
 
You are welcome
 
gods I'm overexcited. My gigantic curved screen is supposed to be arriving today, and I am unable to manage myself
 
what is the first thing you'll do (after setting it up)?
 
probably a video game
(I have a feeling that "whacking it" was the answer you'd have liked ;)
 
I have fond memories of taking my snes to a friends house and having all day king of the hill street fighter competitions. I played Guile and E Honda.
 
@piRSquared SF2 original?
(ie - not the alpha version or extended versions?)
 
correct
 
I completed that on the SNES with every character on level 7
 
Was letting my sons watch Wreck-it-Ralph and was getting all nostalgic about "Hadouken"
 
my newphew had a marvel vs dc fighter game on the ps4
 
5:34 PM
@JonClements that's dedication.
 
I played ryu... he got very, very annoyed that apparently "I knew all the special moves" and he constantly lost
 
oh wait, not dc/marvel, the other game universes, sighs
 
Then all that time spent was worth it. "NinjaPup turns to nephew... 'You are no level 7'"
 
took a bit of explaining that I didn't just "learn this game today"... I played this 20+ years ago :p
 
5:36 PM
I use to rock the NES tetris. No tetris game since feels or reacts the same.
That song is now playing in my head
 
I use to play on tetrinet - not sure if that's still going these days.. but oh boy, I loved that
especially 2vs2 mode
 
Opponent: "What the... How did I just get a wall of bricks?!"
 
or shuffle 'em, and nuking fields blah blah
think I had a 27 minutes game once, constantly nuking the partner, or them me, then the opposition doing the same... got quite interesting
(was also quite a bit of swapping stuff going on as well... that's always... err... interesting)
 
oh man, I missed out on tetrinet. that would've been a blast
 
6:01 PM
Can anyone give me a python code for Warshall's algorithm to find transitive closure of a relation? I have searched for it, but I haven't found any.
 
I'm here
hi
Tetris is magic. It never bores me.
 
Why does this return an empty array
>>> theta = np.linspace(0, (2*np.pi), (2*np.pi)/269)
>>> theta
array([], dtype=float64)
But this doesn't
>>> theta = np.arange(0, (2*np.pi), ((2*np.pi)/269))
 
Those are fundamentally different things
 
I know, let me remove second part
too late, really I'm wondering what I have done wrong in the np.linspace() attempt
 
The third argument is the number of steps you want to use to get from the start to the finish. This should work theta = np.linspace(0, (2*np.pi), 269)
Go from 0 to 2pi with 269 points.
 
6:12 PM
Doh! yup thanks
 
I got a code in Python for Warshell algorithm.. can anyone explain me this code? I am from Math background:
``def warshall(a):
assert (len(row) == len(a) for row in a)
n = len(a)
for k in range(n):
----for i in range(n):
-------- for j in range(n):
------------ a[i][j] = a[i][j] or (a[i][k] and a[k][j])
return a``
How assert works here?
 
It is checking that every row has the same number of elements as there are rows... or that it is a "square" array. If it doesn't it will raise an AssertionError
 
Input is a matrix here
 
Ok, I'm just informing you that the code you posted uses the assert statement to check that the matrix or whatever array like thing is "square"
 
6:29 PM
cabbge
 
6:42 PM
cbg
 
jjj
If I have a dataframe with multiindex, is there a better way of doing something like this:
df = pd.DataFrame(index=index)
df['name'] = df.index.get_level_values('level')
df['name'] = df['name'].apply(some_func)
 
Just used PHP for a class. Now I know why no one uses PHP anymore.
 
6:58 PM
@coldspeed you were blissfully unaware until now?
and o/
@jjj get_level_values returns an Index object which has a map method.
df = pd.DataFrame(
    1, pd.MultiIndex.from_product(
        [[*'abc'], [1, 2, 3]],
        names=['level', 'other']
    ), [*'xyz'])

df['name'] = df.index.get_level_values('level').map(str.upper)
 
@coldspeed class as in OOP, or class as in teacher / learner stuff?
... and yeah, factually speaking, PHP is being used very much widely, and is always in active development.
 
8:03 PM
Random trivia fact: I used to work on the team that the creator of Laravel also used to work on
(leaving that team puts me in good company?)
 
wim
8:34 PM
haven't seen a good question on site for weeks
just crap, crap, crap
 
I haven't been on SO for weeks! (well, not as an answerer anyway)
 
Maybe I should go read some python source and ask some question
 
wim
AoC 2018 leaderboard join code: 119932-f5c26ae6
 
8:57 PM
oh Baby AoC is back
 
wim
9:07 PM
wonder if Marcus will come back and kick all our butts again
haven't seen him around rm6 for a while
 
@WayneWerner in a sense, possibly
 
@AndrasDeak Damned if I know.
 
wim
martin junior
 
9:34 PM
@MartijnPieters don't happen to be in L next week?
 
9:52 PM
I wonder if DSM will be
 
jjj
10:46 PM
@piRSquared thanks a lot, didnt know that
 
Optimization problem: I have 4 variables A, B, C, D and a bunch of modifiers like "+50% to A" or "+80% to B but -50% to C" and I have to pick 8 modifiers so that each variable is above a threshold (A > TA, B > TB, etc) AND the total sum of the 4 values is maximized. Is there a smarter way to do this than blindly trying all combinations?
Order of the modifiers doesn't matter btw, they're all applied to the base value of the variable
 
BFS?
still blindly trying all I guess
 
pretty much
 
If you want to maximize I'm not sure there's a non-trying version in general, right?
anyway, I can't be sniped tonight :P rhubarb
 
rbrb
I feel like dynamic programming might be of help... maybe
oh, one more thing: each modifier has multiple "levels", so for example a modifier might be "+10 A, -5 B" at level 1, then "+20 A, -10 B" at level 2, and so on
 
wim
11:06 PM
There is stuff in scipy for this.
At a high level, you define a "cost function" and then you look at the gradients when perturbing each modifier by the smallest possible amount
google "gradient descent"
 
will look into it, thanks
 
wim
AoC2015 q15 was similar btw
 
oh, neat. Wonder if I can... borrow... someone's code (:
 
@Aran-Fey this sounds a lot like linear programming...which is a math concept and not really "programming" in the way you think about it.
basically with linear programming, you find (usually integer) solutions to a system of linear equations with constraints.
 
Gradient descent doesn't work so well for discrete variables.
(Those variables being "is this modifier on" or "which of several discrete levels is this modifier set to", not A/B/C/D.)
 
11:18 PM
@Code-Apprentice That does indeed look like it'll be useful, thanks
 
@Code-Apprentice: Linear programming doesn't usually require integer solutions. That's integer linear programming, which is much harder.
 
wim
computers have continuous variables now? <sarcasm>
 
@user2357112 oh...I had it the other way around in my head. It's been a long time since I studied it.
thanks for the correction
 

« first day (2965 days earlier)      last day (1983 days later) »