Python Memory Management and Tips Transcripts
Chapter: Efficient data structures
Lecture: Container sizes, Pandas

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Alright, we tried them as arrays.
0:02 That was pretty cool. How about as Pandas
0:05 DataFrames? That's a super useful type that we might want to use.
0:10 So let's go ahead and try to create some series here. So I'll have a "names_series" what
0:16 we're gonna do is create two series and they want to create the dataframe out of
0:20 those two series. I would like to say,
0:22 "pd", but we don't have it installed yet,
0:25 so I'm gonna go on add Pandas, and we're also gonna use NumPy so I'm gonna
0:28 Just write them all in here, and then I just go ahead and let you see it.
0:42 Watch it install. Okay, so we're gonna install these things because in order to work
0:45 with them, they've got to be installed.
0:47 We haven't needed them yet, but here they go.
0:55 We come up here and say,
0:58 "Import pandas as pd". So we'll create a series,
1:04 we'll give it names, the data type is going to be string,
1:10 and then we'll have "ages_series", which comes from ages,
1:15 and it's gonna be a "int8". Then let's go create our DataFrame
1:18 from that "pd.concat([names_series, ages_series]
1:24 axis=1)". And let's just first try to print "df.head()", see what
1:35 we get there. Alright,
1:39 It looks like we've loaded them up correctly and it works.
1:41 So Pandas is awesome. We could do all sorts of advanced stuff.
1:45 How awesome is it in memory,
1:46 though? Let's find out. Let's just grab this, say DataFrame, and let's just
1:55 do it in "size_util.
1:57 get_full_size(df)". run it again.
2:00 How awesome is this gonna be?
2:02 ooooh, it's less awesome. We have arrays and we have
2:07 a big DataFrame. The DataFrame is even bigger than the classes.
2:11 Not super surprising. It's storing indexes and other kinds of things around it.
2:15 So it's super powerful, but it is not super efficient.
2:19 And this honestly surprised me just a tiny bit.
2:21 I thought, you know, it's gonna store numbers crazy efficiently and things like that.
2:25 But, yeah, not so much.