Showing the Results
00:00
The .loc
attribute also allows you to filter the data in a DataFrame when you put an expression in the square brackets, what returns is a new DataFrame containing just the subset of rows that match the expression.
00:12 On one hand, I really don’t like this notation. An expression inside square brackets just doesn’t feel very Pythonic to me. On the other hand, man is this powerful.
00:23
You can get a lot of work done in very little code. So the filter I’m applying here returns those rows whose conjunction count is greater than one. The filtered data is passed to tabulate()
, which will then format it for the screen.
00:37
tabulate()
takes a few arguments to make it prettier. The tablefmt
argument tells it what style of output to use. plain
just prints the results.
00:47
You can get fairly fancy and add borders and column separators and all sorts of other stuff, but I didn’t do it. The headers
argument specifies what column names to use.
00:57
If you don’t pass it, it won’t give you headings at all. I’m passing in the names of the columns from the DataFrame chronological
,
01:05
and the last argument to tabulate()
is floatfmt
. Our angles of separation are floating point numbers and I really don’t want a lot of precision, so I’m formatting it down so it only shows an integer value.
01:18
Once the tabulate()
function creates a table, I then just print it out. Let’s give this a whirl. Going to call the script.
01:31 I have paused the output here to show you a warning from Pandas. The bear is getting a little grouchy. Remember that empty DataFrame that I started with? Well, I didn’t include type information for the columns on the DataFrame, so Pandas wasn’t quite sure what to do with that.
01:47 I then merged that DataFrame with a temporary DataFrame that did have type information. This temporary DataFrame had a date and floats for those columns, and Pandas figured out the types automatically.
02:00 This warning is telling me that mixing the untyped with the typed is bad and further warns me that in the future it might even get angrier about it, so I should change my evil ways.
02:11 The problem can actually be fixed by assigning data types to the empty frame, and you could do that with additional arguments to the constructor. I didn’t do that for two reasons. One, I’m lazy.
02:22 And two, this shows that the suppression that I put in place for the noisy astronomy IERS warnings didn’t affect anything but those calls. It’s great when my desire to show something working means less code for me to write.
02:36 Let me unpause this now, even if I hadn’t paused it, it actually takes a bit on my machine. Doing a hundred iterations takes around three seconds. There’s a lot of math going on in those four lines of Astropy code and what’s on our screen now is our pretty pretty results.
02:52 So on April 19th, 2026, there will be a conjunction of Mercury, Mars, Saturn, and Neptune just in time for Tim Curry’s 80th birthday.
03:07 Now that you know when there will be a conjunction, you might want to know what kind of viewing you’ll have that night. Next up, I’ll show you just what’s involved in getting a good view for any particular thing in the night sky.
Become a Member to join the conversation.