Transcript #108: Spilled data? Call the PyJanitor
Return to episode page view on github00:00 Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
00:05 This is episode 108, recorded December 10th, 2018.
00:10 I'm Michael Kennedy.
00:12 And I'm Brian Okken.
00:12 And this episode is brought to you by DigitalOcean.
00:15 Check them out at pythonbytes.fm/DigitalOcean.
00:17 Tell you more about that later.
00:19 Right now, how are you doing, Brian?
00:20 I'm doing great.
00:21 Yeah?
00:21 Do you find that sometimes you end up with messy data?
00:26 You kind of clean it up.
00:28 You're like, ah, gosh, not again.
00:30 Yeah, I've got empty spots and bad stuff.
00:34 Yeah, anyway, data.
00:36 Yeah, somebody spilled a string where a number was supposed to go.
00:38 Yeah.
00:39 Maybe there is something you can do.
00:40 Yeah, you can get a janitor.
00:41 A Pyjanitor.
00:42 Clean up your janitor.
00:44 Yeah, first project we're going to talk about is Pyjanitor.
00:47 It's a package for cleaning up your data.
00:49 And this has a history in, originally it was a port of an R package called janitor, but now it's grown from that.
00:58 So it's both for cleanliness of data, but also just a really clean interface and convenient routines.
01:06 So it's kind of for anybody working with data that can have problems with it.
01:12 There's a whole bunch of stuff involved with this.
01:15 So some of the functionality includes cleaning up column names, which I'm not sure why you would have bad column names in the first place.
01:23 But if you're pulling it from somewhere else.
01:24 Yeah, like a lot of times people load CSVs into Panda data frames and things like that, I think.
01:29 Yeah, okay.
01:29 So cleaning those out.
01:30 Removing empty rows and columns and identifying duplicate entries.
01:35 There's some stuff that can just happen with data like that.
01:38 But it has a whole bunch of other cool things like telling your system how to deal with empty values and expanding columns and coalescing multiple columns into a single column and a whole bunch of stuff like that.
01:51 That's part of it is dealing with messy data.
01:54 But the other thing is to try to keep your code clean.
01:56 So on the other side of it, it has more of a functional programming style of using it.
02:02 And I'm not going to try to really talk about this too much, but we have a code snippet in our show notes where it shows kind of how you would deal with data frames and doing things like dropping columns and stuff within Pandas.
02:13 And then how that would look in PyJanitor code.
02:17 And it just makes it a lot.
02:19 I think it's more maintainable.
02:21 Sneak?
02:21 Yeah, I really like this.
02:22 It looks super handy.
02:24 It's like a set of utilities on top of Pandas, which is great.
02:28 And I like how they describe this feature you just talked about.
02:31 It's a cleaner, method-changing, verb-based API for common Pandas routines, otherwise known as a fluent interface.
02:40 If you're looking for one word there.
02:42 But that's great.
02:44 So yeah, I think it's a really nice way to work with it.
02:46 It looks really approachable.
02:48 And I do like the fluent interface.
02:49 I really, really wish more things like that.
02:52 Operated that way.
02:53 Yeah.
02:54 For instance, a lot of the functions return data frames so that you can just keep on in a new function to do multiple stages of a workflow.
03:01 Now, this is all around Pandas.
03:03 So if you're doing not just regular data cleaning, but you've got to be working with Pandas.
03:07 But I think a lot of people who do that kind of work probably are.
03:09 So it seems really helpful.
03:10 Yeah.
03:11 So would you consider yourself an expert at Python?
03:13 No.
03:15 I know enough to know what I don't know.
03:17 Yeah.
03:17 I think this is one of the things where it's like you're never really – like there's always stuff that you don't know.
03:22 So you don't ever necessarily feel like an expert.
03:24 Well, especially in this field when we're like – I'm always researching stuff that know more than me about cool places.
03:31 But all in all, I think I am.
03:32 Yeah.
03:32 I would say that you are.
03:33 So I think there's a really interesting presentation done by James Powell.
03:38 And this was recommended to us by one of our listeners.
03:40 I just don't remember who, so I can't give him credit.
03:43 But thank you for whoever sent this in.
03:45 And this is a presentation at PyData 2017 by James Powell.
03:51 And it's a YouTube video.
03:52 And it's not just a little light, you know, here's my quick rundown of the five things.
03:57 It's like an hour and a half sort of deep dive into what it takes to be an expert.
04:02 So basically James says, hey, look, it's pretty easy to be competent with Python, right?
04:08 You can learn a couple of things.
04:09 And whatever other programming language you use, you can kind of like make Python do that.
04:13 But to really understand it properly and take, you know, full advantage of it, write Pythonic code, things like that is a whole lot harder.
04:21 So he runs through some of the things that he thinks people should know.
04:24 And it's really focused at the maybe advanced beginner, early intermediate type of developer who can do stuff with Python,
04:33 but maybe stopped learning about the language and the features when they got whatever they're trying to make work, work.
04:40 Oh, good.
04:40 Yeah.
04:41 So it covers things like the Python data model, you know, otherwise known as the magic methods or dunder methods, meta classes, a bunch of other stuff.
04:49 And it's really nicely done.
04:50 You know, I'm not a fan of presentations that are like, hey, here's seven slides and me talking about it.
04:55 Like, woohoo.
04:56 You know, he just fires up an editor and says, I have no slides.
04:59 The editor is going to be the presentation.
05:01 Let's start talking about these things and just does it from scratch, which I think is a real genuine way to do it.
05:06 So well done.
05:07 I'm going to have to check that out myself.
05:08 Yeah.
05:09 Yeah.
05:09 I've watched some of it.
05:10 I haven't watched all of it.
05:11 I've only watched like maybe half, but definitely watch enough to recommend it to folks.
05:15 If you feel like you're in the stage, like, am I an expert?
05:17 I'm not sure.
05:18 Watch this.
05:19 And, you know, you'll probably get some things reinforced and others maybe feel like, yeah, I knew that.
05:24 That's great.
05:24 Yeah.
05:24 Yeah.
05:25 I would even say it was awesome.
05:26 It's very awesome.
05:27 There's a lot of awesomeness in Python and there's quite a few.
05:33 On GitHub, there's quite a few different awesome lists.
05:36 And so that's what I want to talk about today is another awesome list.
05:40 And this one is called the isosceles triangles.
05:43 No, it's called awesome Python applications.
05:45 It's kind of just a way for you to try to highlight a bunch of different cool applications.
05:53 Because if you're looking for packages to base your own project on, you can look at PyPI.
05:59 But that's not as easy to do with applications because they don't exist in PyPI.
06:03 So that's why this has been created.
06:06 There's quite a few categories already.
06:09 And Mahmoud Hashemi has started it.
06:12 And he wants people to help him out and fill this in because it's kind of hard to find applications sometimes.
06:17 So these are all applications written in Python that are open source that you can look at how they're doing things.
06:23 Yeah.
06:23 I really like this because so often people say, well, I'd like to use Python for this project.
06:29 But to sell this to my teammates and my manager or my company, it would be great to say, well, YouTube is written in Python.
06:36 And I know you think Python doesn't scale, but I'm sure we're doing less than a million requests a second.
06:41 So we'll probably be okay also.
06:44 Having the examples for those kinds of comparisons are really great.
06:48 So this is a little bit like that.
06:49 There's a bunch of stuff for like biology, you know, and like cell profilers and things like that, right?
06:55 Yeah.
06:55 And even like I had to look this one up, ERPs, enterprise resource planning.
07:00 No, I don't need one of those, but cool.
07:03 It's there.
07:03 But a lot of these, one of the things I like about this is there's a lot of custom applications that people end up writing.
07:09 And they know that their problem space is very specific.
07:14 And instead of writing everything from scratch, you could take one of these open source projects and fork it or customize it for your own need.
07:22 And that's one of the benefits of open source, of course.
07:25 But good starting point.
07:26 Yeah, that's awesome.
07:27 I really like this.
07:28 Again, well done, Mahmood.
07:29 And it's just, it's cool to have these examples out there, you know?
07:33 Yeah.
07:33 Do you know what else is cool?
07:34 I do.
07:35 And if I had a cool application, I would like to put my application there in DigitalOcean.
07:40 Absolutely.
07:41 So DigitalOcean is sponsoring the show.
07:45 They've been sponsoring most episodes of Python Bytes, and they're big supporters of it.
07:49 So thank you to them.
07:50 We use them for some of our infrastructure, and it's working out great.
07:53 One thing I want to highlight this time around is their early access Kubernetes project.
07:59 So if you're doing anything with Docker and Kubernetes and things like that, they have some special tools for deploying and managing your containers in the cloud.
08:10 So just go over to pythonbytes.fm/DigitalOcean.
08:13 You can sign up there or go over to the products and just pick Kubernetes and get started on that.
08:18 There's tons of other stuff that you can do as well, but the Kubernetes work they're doing is quite cool.
08:23 Very cool.
08:23 Nice.
08:24 Indeed.
08:25 So the next one I want to talk about is something we haven't covered a ton on the show, but I think has some interesting shadows and parallels with Python itself.
08:34 And that is some governance around Django itself.
08:39 So there's an article called Django Core No More by James Bennett.
08:43 Okay.
08:44 So this is not core as in like some library.
08:47 This is core as in core developers.
08:48 So Django has been around for a long time, 2005 onward, I believe.
08:54 And it's obviously a very polished professional web framework.
08:58 One of the most, if not the most, it's in there fighting with Flask for that title.
09:03 But one of the most popular Python frameworks, lots of amazing apps are built on it.
09:08 But what they're finding is, say, actually, Django as a open source project is not recruiting enough active contributors.
09:16 That's surprising, right?
09:17 Yeah, it is.
09:18 They said one of the reasons they think this is not working so well is they feel like there's these people called Django core developers, and then there's everyone else.
09:28 And if you're not a core developer, well, you probably don't have any business messing around with Django or submitting any fixes or anything.
09:35 Maybe you'll tell a core developer and they can go do it, right?
09:38 But not do it themselves.
09:41 So the proposal, in summary, is more or less to abolish this concept of a core developer altogether.
09:48 Okay.
09:48 Okay?
09:49 So that when people come to look at Django, they don't go, oh, there's this special group of like selected core developers and then everyone else.
09:55 So instead, what they found was in practice, these core developers all had this straight commit bit.
10:02 They could just commit straight to the repo and just have stuff happen.
10:05 But no one was doing that.
10:07 They were all creating pull requests and having a conversation around their changes anyway.
10:11 Yeah.
10:12 And that's how somebody would make a contribution to Django from the outside.
10:17 So they said, let's have a more Democrat, not Democrat, more spread out even way of talking about people who contribute to Django so that people are more likely to come and make contributions.
10:29 Okay.
10:30 So they'll still have some sort of process for deciding on which pull requests to do, right?
10:36 Yeah.
10:37 So now they're going to have two different groups of people who are formalizing this stuff.
10:41 There's mergers and releasers who would respectively merge PRs and then package it up and release it.
10:49 So these are more like bureaucratic roles, like sort of finalizing it, right?
10:54 But the idea is to have PRs and open discussions around issues and PRs.
10:57 And then these folks kind of say, yeah, okay, we're all good with this.
11:00 Interesting.
11:01 Yeah.
11:01 Okay.
11:01 So it's a little bit of a parallel of Guido stepping back and saying, okay, everybody, you guys got to spread out some of this decision making and not just leave it all on my back.
11:11 Yeah.
11:11 I like what they're doing.
11:12 I also like doing a lot of this stuff in the open and having the governance models be sort of an open discussion so that different groups can learn from it.
11:21 So like, for instance, I was listening to your interview about SANIC and they were talking about basically still figuring out how to govern the SANIC project.
11:32 Yeah.
11:33 And so doing all this in the open and having everybody be able to give feedback and stuff is cool.
11:38 Yeah, it's definitely cool.
11:39 Now, I don't believe this is the way that things are.
11:42 This is a proposal for the way that James and folks wants this to be.
11:46 Yeah.
11:47 So kind of take it in that sense, right?
11:48 This is not an official decision as far as I know, but this is the proposal.
11:51 Okay.
11:52 Neat.
11:52 Yeah.
11:53 Cool.
11:53 Speaking of Django, what you got?
11:54 What's next?
11:55 Yeah.
11:56 I wanted to shoo this in.
11:58 I think somebody mentioned this on Twitter.
12:00 Again, I can't remember who.
12:02 Sorry.
12:03 But thanks for everybody for giving us tips on things.
12:05 There is a Django template that is called the WeMake Django template.
12:11 I think, actually, I don't really know who WeMake is.
12:14 I think WeMake is a group that does, like, customer websites and stuff.
12:18 Let me just say, really quick, this is not templates as in Django templates or Jinja 2 or Chameleon.
12:23 This is like, I'm making a project from scratch.
12:26 Like, it generates the project structure, like a project template, not a web HTML template, right?
12:31 Right.
12:31 Okay.
12:32 I guess it should be called a cookie cutter because it is based on cookie cutter.
12:36 More or less.
12:36 Yeah.
12:37 So, it's based on cookie cutter.
12:38 So, you can use, if you, I'm sure everybody's familiar with cookie cutter, you use it to start a project and it pulls stuff off of GitHub and initializes your project and then asks you a bunch of questions.
12:50 But it has a whole bunch of really cool things that you might not actually think to do right away in a Django project.
12:56 They're saying that it is, it's more for larger projects, but I'm sure that a lot of these are, you could do them for smaller projects too.
13:04 But they, it uses a system called Dependabot, which I hadn't heard of before.
13:09 But it's one of those systems to keep your dependencies up to date.
13:13 It's got poetry for package management, which is kind of neat.
13:17 pytest for testing, of course.
13:19 That's awesome.
13:20 One of the reasons why I think this is neat because Django doesn't do pytest automatically.
13:24 So, having somebody initialize that and set it up for you is cool.
13:28 Including things, and then there's some of the other things are mypy for static typing, pre-commit hooks already set up, flake 8, and an extension to the style guide already built in.
13:39 So, you can use that as a template to use your own style guide.
13:42 And a whole bunch of other cool things like Docker integration already, GitLab CI for building and testing.
13:49 And then something that I hadn't heard of before, which is Caddy, which is, I'm going to probably get this wrong, but I think it's something to do with secure web sockets or something.
14:01 I don't know.
14:01 HTTPS.
14:02 Whatever that is.
14:06 Sounds good.
14:06 Yeah, I don't know what Caddy is either.
14:08 I should check it out.
14:09 But it looks pretty cool.
14:10 And, yeah, I think if you're creating Django projects, I think, or any form of web project, there's some for Flask, there's some for Pyramid, there's some for Django.
14:19 I think looking at these more full-featured, more structured starter cookie cutters are really valuable.
14:25 And I think, actually, the biggest value comes to people using Flask, by the way.
14:29 The reason I say that is Django already has a structure, right?
14:33 There's a lot of structure, like static files go here or whatever.
14:35 A lot of stuff is set up when you create a site with Django.
14:37 Same thing with Pyramid.
14:39 You already use cookie cutter templates.
14:41 But Flask is like, well, you create a file, and then you're on your own.
14:44 So all that structure is not anywhere to be seen, but it's still going to have to exist on real apps eventually.
14:51 And so having some projects that you can follow, I think it's really great.
14:54 Yeah, so that's a good segue.
14:56 Not a segue into the next one, but I would love it if people would share with us some of their favorite Flask cookie cutter starter projects.
15:05 Yeah, for sure.
15:06 We can give them a little shout-out in the extra section or something.
15:09 So you want to make it just a straight three of a kind for Django in a row here?
15:12 Let's just wrap it up with Django.
15:14 Yeah, we're already here.
15:15 So you've gone and you created your project with one of these Django templates.
15:20 You've got it working.
15:22 You've done some testing.
15:24 Maybe something wasn't working, so you flipped it into debug mode.
15:26 That's cool.
15:27 Maybe set some other stuff.
15:28 And then you're like, all right, ready to push it out.
15:31 It has like this template you told me about here.
15:34 It already has like integrated deploy steps into the CI build.
15:39 So that's pretty cool.
15:39 You just type deploy and boom, off you go.
15:41 And then a little bit later, something starts happening to your AWS account or your database records that is not so good.
15:49 That might be because you left the debug mode or some other setting on that exposes all sorts of information.
15:58 So there are ways to run Django that is helpful for development, but then you obviously don't want to share that information with everyone else.
16:06 So there's this project called Django Hunter, and it looks for insecure Django's.
16:11 Okay.
16:11 So if you deploy your app, you can point this thing at it and ask it, you know, what's the status of this thing here?
16:17 So the person who wrote it said, why did we create this?
16:20 Well, it's a tool to help identify incorrectly configured Django apps that are exposing sensitive information.
16:26 For example, in March 2018, there was 28,165.
16:31 It's a weird way to write it.
16:32 It says 28,165,000 Django servers.
16:35 Is that 28 million?
16:37 I'm just going to say there's a lot of Django servers that are exposed on the internet, showing off things like their AWS keys, their database passwords and connection strings, etc.
16:45 That you don't want.
16:47 Right.
16:47 So there's this cool tool called Django Hunter, and you can basically point it at your projects, and it will tell you if something's going wrong with them.
16:55 That's cool.
16:55 I love projects like this because Python is so easy to get started on things.
17:00 You can, I guess, jump into the deep end before you're quite ready and have tools like this to help you jump in safely.
17:07 Yeah.
17:08 It's good.
17:08 Absolutely.
17:08 So, you know, it's easy for people to say, well, that was sure stupid.
17:11 You got hacked because you didn't, you know, set the debug mode to false.
17:15 Well, if you're struggling to figure out, like, what does deployment mean?
17:20 Like, I can't even barely get this thing to run on a web server, and I'm trying to understand Linux and databases and firewalls.
17:27 Like, it's pretty easy to overlook that kind of stuff when you're, like, struggling to just make the thing work.
17:33 Right?
17:34 Yeah.
17:34 There's a lot of these settings that, like, you're like, I just want to test this out and show it to somebody.
17:37 I'm not, you know, I haven't been running Django for 10 years.
17:40 So there was actually a conversation either on Twitter or on Reddit about this, and somebody said, yeah, this is great.
17:48 Like, this guy jumped in and says, hey, I've probably one of those, you know, 20,000 servers that are among my early projects that's out on Heroku.
17:56 I accidentally exposed my AWS password and all hell broke loose.
18:00 The problem is, as a beginner, it's not obvious how to separate development and production settings and keep that stuff out of your public repo, of course.
18:09 Yeah.
18:09 Yeah.
18:09 The other thought was, somebody said, you know, there's a reasonable argument to be made that debug should be set to false by default.
18:17 If you turn it on, then maybe you know about it, so you know how to turn it off.
18:20 But if you never turn it on, how do you know, right?
18:22 There's a setting, there's a huge comment right by where the setting is.
18:25 It says, never put this in production with debug equals true.
18:28 But it's like in a settings file you might not ever open.
18:30 Right.
18:30 So if you don't look at it, you know, that's bad.
18:32 So anyway, there's some interesting maybe thoughts around what to do to Django to make it better.
18:37 But certainly having a tool to tell you if something is wrong is good.
18:42 Yeah.
18:42 Okay.
18:43 All right.
18:43 So Django hunters for those Django developers or DevOps running Django.
18:48 People running Django servers.
18:50 Yeah.
18:52 That was good.
18:53 And that was all of our items.
18:54 I want to first give a quick shout out to you, Brian, in our extra section.
18:58 Thanks for having me on your show.
18:59 And I blogged about that.
19:00 So I put a link to the blog.
19:01 But we had a great time talking about what it takes to be a good podcast guest and how
19:06 to prepare for that, which is more broad than just podcast guests, I guess.
19:09 Yeah.
19:09 And we've actually already gotten a whole bunch of positive feedback on that episode.
19:13 So I'm glad we did it.
19:15 Yeah.
19:15 Great.
19:15 Anything else extra?
19:16 You know, I was just thinking Christmas is coming up.
19:19 Just, uh.
19:21 Yeah.
19:21 You know, at least in the United States, there's this weird tradition, but it is, it is a thing
19:27 where like in shopping malls, like a Santa will be hired, a Santa Claus, and we'll sit
19:32 there.
19:33 And there's typically photographers around and like parents will bring their children to
19:37 the Santa.
19:37 And the purpose is the child sits on the lap of the Santa, asks for something probably totally
19:42 unreasonable.
19:43 And they take pictures of it, the whole situation.
19:46 And hopefully the kid doesn't cry and get afraid of Santa.
19:48 So you have a good version of this, right?
19:51 Yeah.
19:51 I'm going to, I'm going to read it out loud because it's a, it's a comic, but it's a, it's
19:56 posted.
19:56 It's hilarious.
19:57 And it was posted by a change log on Twitter.
20:01 This little girl sits, is sitting on Santa's lap and she says, for Christmas, I want
20:05 a dragon.
20:05 Of course says, Santa says, be realistic.
20:08 Okay.
20:09 I want enough donations to support my open source work with a response of what color do you want
20:14 your dragon?
20:14 That's so awesome.
20:17 I really love it.
20:18 It's sad that it's true, but, yeah, it's pretty awesome.
20:20 Be realistic.
20:21 Yeah.
20:21 What color do you want your dragon to be?
20:23 All right.
20:24 Well, I thought I'd throw one in here for you as well.
20:26 it has nothing to do with any seasonal stuff, so this is good year round.
20:31 Okay.
20:31 Has more to do with race conditions, deadlocks, and that sort of weird timing problems you run
20:36 into with multi-threading.
20:37 Yeah.
20:37 Yeah.
20:38 So you've heard the joke, why did the chicken cross the road, which has all sorts of weird
20:42 answers, but sometimes just to get to the other side, right?
20:44 Why did the multi-threaded chicken cross the road?
20:47 I don't know.
20:47 Why?
20:47 Why?
20:47 Road the side get to the other of the two.
20:50 Ask me again.
20:51 Why did the multi-threaded chicken cross the road?
20:54 The side of to the road other get.
20:56 There's always ground love.
20:58 It's always different.
20:59 I love it.
21:01 That concludes the joke section, I suppose.
21:03 Yeah.
21:04 So, yeah, we'd also like, we're both sort of silly people, and we'd like to have some feedback
21:09 as well from people to see whether or not we should keep a joke or two in the episodes,
21:15 or actually just whether or not we should.
21:18 So that'd be great.
21:18 Yeah, it sounds good.
21:19 And if you have good jokes.
21:20 Yeah.
21:21 Send them.
21:21 Send them.
21:22 All right.
21:22 Well, Brian, thank you for doing this, and everyone, thank you for listening.
21:25 Thank you.
21:25 Bye.
21:26 Thank you for listening to Python Bytes.
21:28 Follow the show on Twitter via at Python Bytes.
21:30 That's Python Bytes as in B-Y-T-E-S.
21:33 And get the full show notes at pythonbytes.fm.
21:37 If you have a news item you want featured, just visit pythonbytes.fm and send it our way.
21:41 We're always on the lookout for sharing something cool.
21:44 On behalf of myself and Brian Okken, this is Michael Kennedy.
21:47 Thank you for listening and sharing this podcast with your friends and colleagues.