« first day (3383 days earlier)      last day (1548 days later) » 

12:43 AM
The dataframe slicing in pandas still hasn't really clicked for me. I don't know when a slice makes a copy or is just a view. Maybe I should write a DSL wrapper...
 
12:53 AM
[removed wrong history] Sorry, seems I was wrong, it seems not even slicing is safe for dataframes
according to an example here not even dfc['A'][0] = 111 is supposed to work, which is the most trivial slicing case
so my numpy experience is irrelevant
 
1:05 AM
Are dataframes a numpy thing or a pandas thing? I thought they were pandas.
 
Yes, pandas
But pandas is mostly built on numpy so I can guess a lot of things (and way miss the mark on others)
Numpy only has arrays
 
 
2 hours later…
3:16 AM
Is there a Python lib for modelling cities?
 
 
4 hours later…
7:16 AM
hi
 
 
3 hours later…
10:16 AM
Hey guy, I want to open a 250MB xml file and parse through it But first I need to see its structure, I am struggling to do so as my browser cannot open it. Do you have any ideas on how to open it?
 
use a text editor?
XML is plaintext
 
yeah I want it to keep the structure though
 
I fail to see how a text editor would not do that.
Can you clarify what you mean by "structure"?
 
10:32 AM
I think they want to be able to see how stuff are nested etc.
 
as in, nicely display different nesting levels? indentation and collapsing of children?
 
The structure I mean is the as @AndrasDeak said.
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
  <book category="cooking">
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>
    <year>2005</year>
    <price>30.00</price>
  </book>
 
11:00 AM
Hello, a most random question.
Is there a special tool to use or A sample code to follow, To save the data from mail to spreadsheet automatically?
I know, I could use export option which has already included in Outlook and Gmail. But I wanted the process to happen automatically, Whenever I get a mail a process to run in background and save the desired data automatically
 
Triggering a python program every time your mail client receives a mail is going to be difficult, if not impossible
 
Yea, with python is kind of difficult
is there any option?
 
11:19 AM
i can envision a couple different ways to achieve this kind of behaviour in python, one would be some polling based program that just runs and checks every 10 second or so, another would be some kind of push notifications api if they work. Both approaches will involve trying a few things out first before deciding whether it's worth it or not.
Also consider whether you really need it to run automatically that often, or can you afford to have it run once an hour or something more sane instead
So i suppose, to answer your question: figure out your tool to download data from mail to spreedsheet, be it python based or some macro in some other language, and then set up a polling/scheduled/noficiation based setup around it that just fires the code often as you need it
Do the first part first, and then worry about the second
 
Something useful.. I will look for it. Hope I go in the right direction, for both the parts
 
 
1 hour later…
12:52 PM
I'm unsure quite why d.update({key: value}) seems to be becoming an accepted spelling of d[key] = value, but I've been seeing this in code reviews for several years nmow. I suspect it comes from Javascripters, but I'm not sure.
 
I've encountered the misconception that container[key] is only array indexing (àla C). As a result, some people don't make the connection that dict[key] is even a thing.
 
I found that I have done this myself when setting 2 or 3 key-values at once. I (think!) I wouldn't do this for just one key though. And I'm the last person you would consider a JS'er
 
# any more variants?
d[a] = 1
d[b] = 2
#
d[a], d[b] = 1, 2
#
d.update({a: 1, b: 2})
 
1:08 PM
for k, v in zip([a, b], [1, 2]): d[k] = v

d = {a: 1, b: 2, **d}
 
1:42 PM
Ooops, should be d = {**d, a: 1, b: 2}
 
1:54 PM
@MisterMiyagi Is it also possible that our flood of new Python users coming by way of data science, ML, or other pandas-related field, think that sth['XYZ'] is just for accessing column 'XYZ' of a dataframe?
 
@PaulMcG I'd prefer not to gaze long into that abyss. Scary things might gaze back.
Well, scary things do gaze back, judging by the pandas tag on SO.
Without wanting to point fingers, my subjective impression is that cargo cult is a lot more common in that group. Too often is a frustrated "WTF?!?" answered by an honest "because the interwebz said so".
 
code written by newbie programmers is already bad enough, so it's not much of a surprise that code written by newbie non-programmers is even worse
those are people who want to get stuff done, not learn how to write code
 
2:15 PM
I mildly sympathise with that notion, coming from the same camp. Then again, since the means to get stuff done is writing code, not learning how-to is... suboptimal.
 
Yeah, but to be honest it's easy to misjudge that. When I started writing JS I never actually bothered reading a JS tutorial either, I just googled the bits and pieces I needed
('course, it's a bit different because I already knew how to code, but still)
 
2:30 PM
that's a huge difference, to be honest
if someone learns the first language properly they already have a much better chance to conceptualize a new language
of course one might still pick up anti-patterns, but at least it's not "not even wrong"
 
3:01 PM
I don't think those people realize the depth of what they're getting themselves into, though. I think the thought process is like "I don't want to learn programming/python, I just want to learn this tiny subset of programming that I need for my job"
which, sadly, doesn't really work like that
 
3:14 PM
not when everyone and their uncle has a programming tutorial video on youtube
 
Well, the tutorials we got in university weren't exactly shining examples either.
"I don't want to teach programming/python, I just want you to learn this tiny subset of programming that you need to do my job"
 
hah, that's the next problem. Even people who have been programming for a while still aren't capable of correctly judging how much there is to learn / how bad they actually are.
 
addendum: sed 's/python/C/'
 
...I just remembered the mess I'm currently working on and now I regret talking bad about other people.
Well, a little bit.
 
you don't need to be a good chef to tell if the food is bad
 
3:27 PM
good point
 
there's obviously some more Dunning--Kruger involved in technical matters, but still
 
morning cabbages, all!
 
cbg
 
jolly good day to you as well
 
"jolly good" I haven't heard that in a while. What a fun surprise!
How's your day going?
 
3:34 PM
tbh I'm starting to think that I try too hard to write good code sometime. I've hardly made any progress in the last week because I was paralyzed trying to find a good program architecture. Maybe I should just, y'know, write bad code that works
 
@inspectorG4dget I currently sit through some mandatory-corruption-prevention-seminar-online-course thingy. That's almost as entertaining as watching cat videos.
 
@Aran-Fey no reason you couldn't start with bad code and refine it
 
@Aran-Fey I've found it very productive to write bad code and have an exit strategy for it from the start.
 
@MisterMiyagi ouch! would they be able to tell if you were watching internet cats on your laptop the whole time?
 
But I have no exit strategy though :/
 
3:38 PM
@inspectorG4dget Nah, it's just walls of text and multiple choice. Very modern. But the content is so hilariously staged, it's cute.
 
It's better than making it so boring that nobody pays attention I suppose
 
"Someone offers you money to do something wrong. Do you accept?"
[ ] Yes -- [ ] YES!!! -- [ ] No, because I'm a good employee
 
that last one is exactly something that a corrupt employee would say
 
Yeah, part of me thinks it's the psychology department playing tricks on the other faculties.
 
that is what security developers ask everytime
haha
 
3:46 PM
@MisterMiyagi this is hilarious!
 
"Your immediate boss asks you to do something you think is wrong."
[ ] I do it anyways -- [ ] I immediately call compliance department
This is surreal.
 
Let's be real here - 99% of people would do what their boss tells them to do
Unless it's something like committing murder
 
Then it's just 98%?
 
something like that
 
The scary part is that the folks making this course mandatory for me also roughly decide about the mandatory lectures on programming.
Which kinda explains why we scientists are so good at the business.
 
4:07 PM
Hmm, you said something about the LHC earlier. With CERN I can certainly understand all the protocols
 
fun fact: one of the guys on my team worked at CERN when they were searching for the Higgs
 
4:20 PM
@Aran-Fey No matter how hard I try to write good code I almost invariably cringe when I look at my old code. I've come to accept this as part of the programmer's burden: "everything I've every written is rubbish."
 
makes you want to just go "bugrit"
 
@MisterMiyagi The way out is merciless refactoring, allegedly. "I'm just going to take a week to refactor this ugly code." "No you aren't, you;'re going to start work on our next feature" is how it often goes.
 
Yup. "Technical debt" ...
Oh well, got a little shopping to do now. Rhubarb, all, bugrit.
 
rbrb
 
4:44 PM
The problem with embracing my rubbish code is that it doesn't work yet and I'm having a hard time fixing bugs in this mess :D
Although if I do manage to fix it, most of the code will actually be decent, save for 1 or 2 ugly parts
 
@holdenweb Not much of a way out if good code isn't wanted. Thankfully, we've had a lot of projects in the community fail due to bad code. That gave us a lot of leeway to push for reviews+testing+static analysis.
 
5:14 PM
morning cabbage
 
5:34 PM
cbg
 
hello guys i got this error in python
SyntaxError: 'return' outside function
the problem is return already inside function
anyone can help me please
tecno_subject_how_many = int(input(" How many subject have for this student : "))
i = 0
while i != int(tecno_subject_how_many):
i = i +1

subject = input("\nEnter Subject Name : ")
time = input("Enter Time for subject : ")
days = input("Enter Days for subject : ")

subject_many_for_student = int(input(" \n \ndoes student have other time and days for same subject ? if yes write how many classes have in number : "))
b = 0
if b != subject_many_for_student:
b = b +1
stime = input("Enter Time for subject : ")
 
wim
@Aran-Fey gaming for the AoC leaderboard might help with that
It's a mad scramble to get something that works at midnight, and then you polish it up later.
 
this is my code and and error in line 18 (return b)
thank you
 
@KutaibaHMomani Please format your code properly. See the formatting guide.
at glance, I don't see a def anywhere in that blob though
So you get the "return outside function" because you use return outside of a function...
 
crazy how that works
 
wim
5:43 PM
on the harder problems it's usually a net time-saver to write the tests first, and once you've solved it, you have the tests there to refactor out the uglyness later. which is actually a pretty good pattern in professional life (with deadlines) too.
 
This may be a language misunderstanding: return outside function means that you have a return statement that is not inside a function (which you create using def).
 
unrelated note: Just saw a talk by dabeaz where his editor took λf:λx:x and expanded it to lambda f: lambda x: x. Want.
 
wim
was that his Lambda Calculus pycon tutorial?
 
okay thanks guys , i fact i don't use def so i will try it now
thanks all
 
@wim Hmm. Maybe I'll try AoC again this year
 
5:45 PM
someone that use vscode? i have this problem when i try to open a new jupyter notebook with python plugin 'Cannot read property 'uri' of undefined'
 
def is a good one to learn to use
 
@wim yeah. So far (53:00) one of the more accessible lambda calculus talks.
 
@PaulMcG yes i think that , thanks i will try
 
wim
that stuff is interesting but you may as well learn lisp
next to useless in Python
dabeaz has a knack to make any topic appealing, however! good teacher
 
can i ask please other q

in this code when i write 4 for example it's don't ask me enter 4 times why ?

subject_many_for_student = int(input(" \n \ndoes student have other time and days
for same subject ? if yes write how many classes have in number : "))
b = 0
if b != subject_many_for_student:
b = b +1
stime = input("Enter Time for subject : ")
sdays = input("Enter Days for subject : ")
print(stime + sdays)
 
5:52 PM
because there's no loop in your code
looks like that if should be a while?
 
@Aran-Fey aha ok right you are right , i will write while loop and try it thanks for point
 
@KutaibaHMomani - please look at the post on how to format your code
The unindented Python code is hurting my brain
 
@PaulMcG hhh sorry for that , where is the post please
 
There is a starred post on the right hand side of the browser window, it directs you to sopython.com/wiki/…
 
@wim Just watching it for educational purposes. The academic in me likes the idea of lambda calculus. The pragmatic in me can't stand the fanwank most tutorials have.
Plus, LISP in Python went by so quickly...
 
6:20 PM
storing a table name in a database column seems so strange to me
am I the only one?
@KutaibaHMomani Your code doesn't have def anywhere, so the return isn't inside a function.
 
But...hear me out...what if it is?
 
wim
@Code-Apprentice That is actually a pretty common pattern in SQL.. search "generic foreign key"
 
6:36 PM
@wim In my particular situation, all of the tables named in said column have the exact same shape. So a real foreign key would be sufficient. And would make writing queries so much easier.
 
user12384956
6:56 PM
I have a listed dictionary d = '[{"date":"2020-01-20","stats":[{"metrics":{"blocks":8,"bounce_drops":6,"bounces":35,"clicks":507,"deferred":1,"delivered":2770,"invalid_emails":7,"opens":4812,"processed":0,"requests":2822,"spam_report_drops":1,"spam_reports":0,"unique_clicks":378,"unique_opens":1695,"unsubscribe_drops":0,"unsubscribes":0}}]}]\n' I want to get this into tabluar form. I tried import pandas as pd
from pandas.io.json import json_normalize

# lets say d is your dict
f = json_normalize(d)
 
The one time someone says "I have a dict" rather than "I have JSON" it's actually JSON :/
Could you elaborate how exactly you want to convert this nested amalgamation of dicts and lists into a table?
 
user12384956
I want it to look like the below in my csv where i have the resepective headers and the stats below each:

blocks bounce_drops bounces
5 6 16
 
Uh, so there's only 1 row of data?
 
user12384956
yes
 
user12384956
every metric has one stat attached to it as you see in the json df. for example click = 508, bounces = 35 and so on
 
7:04 PM
@hartvillezillow for future reference please see our code formatting guide to chat and practice in the sandbox if necessary
 
user12384956
okay I will thank you. Im a first time chat user. apologies
 
It's alright, chat formatting is weird
 
But once you get used to it, your posts are much more readable - thanks for making the effort!
 
d = json.loads(d)
d = d[0]['stats'][0]['metrics']

cols = ['blocks','bounce_drops','bounces']
table = {col: d[col] for col in cols}
Something like that
 
user12384956
json.loads is after importing which lib? im new to py
 
7:16 PM
import json
 
user12384956
7:29 PM
table
Out[15]: {'blocks': 8, 'bounce_drops': 6, 'bounces': 35}
 
user12384956
This converts it as above. But i want it as a dataframe
 
user12384956
blocks bounce_drops bounces
5         6                   16
 
I don't know pandas, but I'm sure you can figure out how to convert a dict to a dataframe
 
Why create a dataframe with one row?
 
user12384956
its a daily report
 
7:35 PM
That you're going to append to another dataframe daily, or a daily report and you're looking to aggregate an entire year from separate JSON objects in one go?
Side note; how on earth does my autocorrect know the word "datagrams"?
 
user12384956
it will append to the same csv file everyday after SSIS pulls in the data
 
Oh. You're not just using pandas to append to a CSV are you?
 
user12384956
nope.
 
user12384956
basically want each header to display stats in a tabular format and then I will export it to a csv
 
7:53 PM
Using pandas to update a CSV is like FedEx's original package traffic model. Even if you are sending a package next door, they put it on a plane, fly it to Memphis, put it on another plane, send it back to your local airport, and then drive it to your next door neighbor's house. It's really roundabout, but it sure is convenient.
 
unformatted code is invisible to me starting now :I
 
8:10 PM
@KutaibaHMomani What Aran-Fey means is, you really need to follow the formatting instructions. In summary, paste your short code snippet in a post all by itself (no additional message text), then click the "Fixed Font" button on your browser, or Control-K to format the code as a fixed-width font. Your Python code is really pretty much unreadable without doing this.
 
 
1 hour later…
9:25 PM
I am just curious, which version do you prefer the most?

1)
		while task.nextTask:
			sTime = task.scheduledTime
			if sTime == f"{hour}:{minute}":
				return True
			task = task.nextTask

2)
		while task.nextTask:
			sTime = task.scheduledTime
			if sTime == f"{hour}:{minute}":
				return True
                        else:
			        task = task.nextTask
I always find myself shifting between including redundant "else" clauses and not including them.
What about you?
 
definitely the one without the else
if there was a return in there then it'd be alright, but like this it's confusing
 
hmm interesting, do you always avoid the inclusion of redundant else clauses? Or do you sometimes include it for the sake of readability?
 
I include them sometimes... if they contain returns
 
@SebastianNielsen should it be while task instead?
 
I am sorry what?
The code should be as it is
 
9:35 PM
You have while task.nextTask. This will not return True if the very last task would match the if condition.
 
My very last task is a dummy task, so no worries in that regard
 
You could avoid needing a dummy task on the end of the list then.
 
How?
Uh, I think I know how
 
By changing the while to while task instead of while task.nextTask
 
Yea, that's what I thought
 
9:39 PM
@SebastianNielsen I avoid else if the clause is of a different kind. So in this case I'd pick 1) because the "branches" do different things.
 
Ahh, I see, that's a great "algorithm" to decide whether to include it or not.
 
9:50 PM
So this returns True or None? That strikes me as odd.
 
If you are speaking of my code, @PaulMcG, I actually have a return False after the while loop, I just excluded it here.
 
I was
 
10:02 PM
I think for the first time in my life I've written code that I'm actually too stupid to debug
...maybe it'll help if I draw a flowchart or something
 

« first day (3383 days earlier)      last day (1548 days later) »