« first day (4122 days earlier)      last day (809 days later) » 

user14803978
12:57 AM
So I have some buttons.
They have commands.
filemenu.add_command(label = "0", command =lambda -> print(0) )
filemenu.add_command(label = "1", command =lambda -> print(1) )

Each Menu Button prints out what you would expect.
0 prints '0'.
1 prints '1'

What I dont understand is :

for i in range(0,2)
filemenu.add_command(label =i , command =lambda -> print(i) )

0 prints '1'
1 prints '1'

Does anyone know why 0 is printing 1, and how I can rectify this?
 
user14803978
Thanks
 
1:19 AM
had to be in the yamming US again didn't it... sighs
 
2:13 AM
What, don't you like us over here?
 
@MattDMo haha.. not a fan of flying is all
 
I know a guy who rents paddleboats...
 
yeah... 'cos that'll be really nice across the atlantic...
 
2:29 AM
They really need to get working on that transatlantic train tunnel
 
 
6 hours later…
8:52 AM
morning cbg
 
9:52 AM
@roganjosh You actually made me question my language and I discovered I've been using the wrong word for "insoluble" this whole time
 
 
2 hours later…
12:12 PM
Hey all, I have a dataframe, df, and I want to create a dictionary for several keys out of this df. Lets say; my df includes data on different keys (Bob, Paul, Andrea). It includes the time of their birth (datetime64[ns, UTC), their weight, and other float, object and integer values. Now I want to create a dictionary that says : "bob": df(agecolumn(age of bob)), df(weightcolumn(weight of bob), ... etc for all the people in the df. How can I do this?
I know how to create a dictionary, but Idk how to assign the values in my df that belong to this respective person to this dictionary: I tried: "Paul": df.Paul['AGE'],df.Paul['Boook'],.. etc but it doesn't work
 
Explaining the structure of your data is all fine and dandy, but showing some sample data would also help a great deal
 
is your df simply 1 row per person?
 
Describing things is hard. Showing things is easy. Often you need to do both, but if you're not showing anything, you're doing it wrong
 
@ParitoshSingh no, it is more complex. It is like 500 dates, on each date there is a Person and different values assigned to this person.
Okay, I try to visualize it, sorry!
 
12:20 PM
Having a sample of the desired output would help too.
 
Do you guys know which format 2022-02-03T16:00:00.000 this is? Came across in an API
 
I bet they just have the index and columns reversed
 
@DelriusEuphoria Not sure, but I know datetime.fromisoformat() can parse it
 
that usually means that it's ISO format
 
Is there only one of those? I have no idea
 
12:24 PM
at worst it's an ISO format
we could look up the datetime docs, but I know I won't
 
People.dtypes
date datetime64[ns, UTC]
id float64
Name object
weight float64
new_weight int64
amount int64
added int64
dtype: object
 
@Aran-Fey Then I'll try parsing it with it then
 
@Baobab Does df.loc[df.Name == 'Paul', :] work?
 
I want: Dict = {"Bob":[(Name of Bob)],[(weight of Bob)], [(new_weight of Bob)], "Julia": [(Name of Julia)], [(weight of Julia)], ...}
@AndrasDeak I'll try that, thanks already!
 
That's a syntax error
 
12:27 PM
Dict is a terrible name for a dict
 
I'm guessing you mean {'Bob': [name_of_bob, weight_of_bob, new_weight_of_bob]}?
 
Why do we need the name of Bob when it's Bob?
 
Reasons
 
Perhaps he's actually named Robert?
 
@MisterMiyagi exploding head emoji
 
12:29 PM
@Aran-Fey yes, just that I don't know how to assign the name of bob to bob. Because my columns are just "name" , but I need the exact name of Bob, not just any name, if that males sense. So I'm not sure what to actually put into the bracket
 
It could be that we're all witnessing an internal spy conspiracy uncovering situation thingy.
 
@Baobab you're mixing up "what I want" and "what I think I should do to get it". Aran asked "what you want", and the answer seems to be "yes". Then we'll help figure out "how to get it".
 
@Baobab This and also this is too vague. Give us an actual dataframe to experiment with, and the actual dict you want to get as output. We're not wizards; we can't spit out the code you want in the blink of an eye. We need data to work with, data that we can test our code on. It's your job to provide us with that data.
 
What you want is not "[(Name of Bob)],[(weight of Bob)], [(new_weight of Bob)]", it's "[name_of_bob, weight_of_bob, new_weight_of_bob]"
 
Is "provide someone with something" even correct english? Eh, whatever
 
12:32 PM
I think it is
 
12:43 PM
@Aran-Fey you're all good
 
yay \o/
 
In English-related news, a data scientist that I don't know has added me on LinkedIn and his history seems to be medical work. However, he's seemingly misheard the title "Chief" so all of his history is "Cheap Medical Director", which isn't exactly a flattering title!
3
 
oof
 
That's hilarious!
 
 
1 hour later…
2:03 PM
If I have a django view that saves data on form.is_valid (plain text) then signals on post_save to another model that saves another set of encrypted data, what is a good unittest strategy I may apply here?
How are these sorts of scenarios typically tested, if at all?
 
2:33 PM
@hello write a unittest for signals, then write unittests for the Django view
 
Hello Python community.

I have a device generating logs and I want to manipulate the logfile for data analysis.

At the beginning of the Logfile I have got lines indicating the Log types and structure and then the logs that are generated.

The log are organized as follow:
- BATT, Timestamp, SerialNumber, LevelIn%, Cycles
- SYSERR, Timestamp, Code, Message
- HUMIDITY, Timestamp, SerailNumber, Value
- BATT, 12345, 234, 12, 355
- BATT, 12452, 264, 29, 651
- HUMIDITY, 12455, 098875, 234
- BATT, 12459, 264, 28, 651
 
3:28 PM
If all of your data is numbers and strings, then it probably wouldn't be too hard to write your own parser from scratch. You could probably make use of ast.literal_eval for the lines other than the logtype/structure headers
I'm also wondering if you could tweak the format of the lines a bit to make parsing even easier. For example, putting square brackets around every line so it becomes basically valid JSONLines
 
you could always just feed it to pandas first, or separate out all lines of one prefix (like BATT) and then feed that to pandas. and let it take care of everything
 
3:57 PM
columns are not homogeneous
 
4:10 PM
pandas still eats it and fills Nans at the end for the shorter rows if you do the "pandas first then separate" approach.
though i think im in favour of separating all common prefix lines and then letting pandas take each group one by one
 
I meant type homogeneous. Seems like a mistake to make those df columns.
 
Yeah, separating by prefix first would save you some type weirdness
 
@ParitoshSingh I tried that, loading the CSV file but I can only drop lines after the first one. I didn't find how to redefine the header to other than the 1st line
@Kevin Indeed for the JSON it could be an evolution
@Kevin I agree
 
Oh, is it already in valid CSV? Then you don't need any custom parsing
Ok, so the csv module can take the data from the file and put it in a collection of lists. And I assume pandas knows how to turn lists into a dataframe. So what else needs to be done?
 
@Akhneyzar to answer this part, theres a header argument, if you pass it to header=None iirc, that gets it to treat every line as a row. if you do the pandas first approach, you'd still need to write further logics to separate out the rows from each other later. So, deal with the common prefix lines first. So, for something concrete: can you write code that reads the file as lines, and then separate out the lines into separate groups based on their prefix? perhaps using a dictionary or so on.
@AndrasDeak ah, i see what you mean, yeah you're right
 
5:03 PM
@Kevin When you say "write your own parser from scratch" is there typically more to these sorts of tasks than reading each line, in this case, a log file and applying regEx on it? Or is there some other python construct that are more robust than this sort of parsing?
 
depends on the task, but youve got the gist of it. it may not necessarily be regex, sometimes simple python string operations suffice, sometimes regex itself is not enough
 
Ahh I missed to answer, I'll try to catch up later
Gotta catch the train
 
5:40 PM
@hello If strings are involved, I don't trust myself to write a regex that can properly catch all unusual cases, such as strings that contain quote marks and apostrophes and slashes etc. And worse, any data format that allows nested parentheses/brackets is downright un-regex-able.
I may have mentioned ast.literal_eval already. It can parse any string that is a syntactically valid combination of number/string/list/tuple/dict/set literal values. Quite handy if the thing you're parsing just happens to be python-like.
 
Ha! I feel the same way. For reference, I have several network-related logs (which I believe are fairly standardized) parsed using a single py file with a lot of if statements using RegEx to match stings etc. Maybe I'm overthinking it a bit.

I'll look into ast.literal_eval
 
>>> import ast
>>> s = """[1, [2, {3, 'foo'}, {4.0: 1e-1, "five": 6}]]"""
>>> ast.literal_eval(s)[1][2].keys()
dict_keys([4.0, 'five'])
 
 
1 hour later…
6:52 PM
cabbage
 
 
1 hour later…
8:00 PM
Today's random musing while I wait for some pasta to cook. Where does the sound come from with water reaching up to boiling point? There are no visible bubbles
 
Wait, does that really make a sound? I don't think I ever noticed
It's also possible that I did notice and immediately forgot about it again because it didn't seem noteworthy, but either way this is a bit of a shocking revelation for me right now
 
first article. You can hear a kettle heating up before it boils, I assume?
 
@roganjosh microscopic ones, probably cavitation
 
I would have gone with cavitation, and that's what this article lists as one suggestion, but I'm jumping between curiosity and actually cooking :P
 
@roganjosh I honestly couldn't say. I have no memory of this sound
 
8:09 PM
Water evaporates (being heated above its boiling point locally), bubble expands, but the hydrostatic pressure of the water column collapses it back again. Or something like that. For boiling to happen you have to 1. heat to the boiling point, 2. invest the latent heat of evaporation, 3. grow bubbles large enough to defeat hydrostatic pressure
that's also why thick things will boil like ... BLOOP... BLOOP...
 
@Aran-Fey I assume you have an electric kettle? Why isn't it silent? All it is is a heating coil, a metal plate, and liquid. Why does it make any sound at all?
 
Nope, no kettle. Just an electric stove and a pot
 
@AndrasDeak I suspect it really is cavitation. Once it gets close enough to boiling, you can see the bubbles collapse
 
yup
 
@Aran-Fey you can hear it before it comes to the boil, though?
 
8:13 PM
it's probably that the kettle will just smash the water with 1200 W right away, and until there's a temperature gradient that induces a current in there, the lowest water layer gets almost-boiled temporarily
@Aran-Fey electric kettles are super loud, right at the start and right before the end. Probably has to do with the closed metal cylinder shape.
 
What intrigues me on the cavitation explanation (even when it's in a pan) is that you can hear it so far ahead of the boiling point. I guess that temp gradient is pretty severe
 
@roganjosh *shrug*. Evidently you're right about it making a sound though, seeing how Andras is agreeing with you, so don't mind me
 
@Aran-Fey Whack 2 or 3 cm of water in a pan on full heat
 
that won't be the same
 
cm of depth*
 
8:16 PM
I have an induction plate, as close as it gets to an electric kettle. Not even close.
 
It should be, I have a halogen stove and the pan was "roaring" before it started boiling?
 
right before, sure. But not right at the start, right?
 
The depth of water will be important to give the pressure to collapse the bubbles, though
 
Right before boiling it's easy to understand why it's loud. I think the roar right after startup is a lot more confusing.
 
@AndrasDeak No, not right from the start
 
8:19 PM
OK
 
Yeah, ok, then the initial roar confuses the pair of us. I can buy cavitation if you make an extreme-enough gradient, but turning the kettle on and having it in, what, 20 seconds, when it takes a couple of mins to boil, makes it even more intriguing
 
dunno
I haven't paid that much attention to boiling water, to be honest
 
I was bored and sans phone, so what else am I supposed to do but question the very depths of reality? This is my life. Feed me pictures of cats or existentialism sets in
 
funny, ive always wondered about this but never looked it up. i do have a theory for the initial boil, it's that before convection is set up, theres just a mismatch of temps when the part closest to the bottom suddenly rises in temperature rapidly, while the part above doesnt.
what causes the sound, i am not a 100% sure, but i suspect convection shuts that sound down, so it's only there till convection isnt.
 
Once there's enough convection going, it's easier to explain with cavitation. The water in contact with the heated surface boils and immediately collapses because the heat is transferred from the surface of the bubble. I'm certainly less sure about the early stage, where the water is basically at room temperature and you still hear the sound
Maybe a kettle element can boil water in contact with the base of the kettle in 10 or 20 seconds, but that's some going!
Or, perhaps, the base of the kettle really is boiling water within seconds. I guess that's the only sane explanation
Actually, I've been totally ignoring the fact that there are actually gases dissolved in water too. I think I'm satisfied with the explanation of that article
 

« first day (4122 days earlier)      last day (809 days later) »