Why is Python so popular? There's plenty of room for debate on this, but one solid reason is it's
easy to adopt, easy to use, and caters to people who are not quite developers, data scientists, but
need to get some computing done. Do you know where the largest untap set of those people hang out?
Excel. That's why it's super exciting that Python is now going to be built directly into Excel.
Just go into a cell and type equals pi, and you're off writing full Python 3 code that is backed by a
lightweight anaconda distribution of Python. We have Dr. Sarah Kaiser here to give us the rundown on
Python and Excel. This is Talk Python to Me, episode 445, recorded live and on location at
Microsoft Ignite in Seattle, November 16th, 2023.
Welcome to Talk Python to Me, a weekly podcast on Python. This is your host, Michael Kennedy.
Follow me on Mastodon, where I'm @mkennedy, and follow the podcast using @talkpython,
both on fosstodon.org. Keep up with the show and listen to over seven years of past episodes at
Talk Python.fm. We've started streaming most of our episodes live on YouTube. Subscribe to our YouTube
channel over at talkpython.fm/youtube to get notified about upcoming shows and be part of that
episode. This episode is sponsored by Posit Connect from the makers of Shiny. Publish, share, and deploy
all of your data projects that you're creating using Python. Streamlit, Dash, Shiny, Bokeh, FastAPI,
Flask, Quarto, Reports, Dashboards, and APIs. Posit Connect supports all of them. Try Posit Connect for free
by going to talkpython.fm/Posit, P-O-S-I-T. And it's brought to you by the PyBytes Developer
Mindset Program. PyBytes' core mission is to help you break the vicious cycle of tutorial paralysis
through developing real-world applications. The PyBites Developer Mindset Program will help you build
the confidence you need to become a highly effective developer. The link is in your podcast player show
notes. Sarah, welcome to Talk Python to me. Hey, how's it going? Hey, it's going super well, super well here
at Ignite for one more time to talk about cool stuff with Python and things going on. This time it's going
to be Excel and Python. It's like Reese's Pieces. You got your chocolate and my peanut butter. Like,
what's going on here? I mean, the cats and dogs, are they living together? What's happening?
The old school and the new school. That's right. The open source and the not?
Yeah, yeah. My background is I've been a data scientist for a long time. I did my PhD in quantum
computing, in like experimental physics stuff. So trying, I actually, my first programming language
was Mathematica. And that was actually what got me hooked on kind of the notebook sort of interface.
Yeah, okay. Well, normally people say their first programming language when that's the background is
math lab. Yeah. I would say Mathematica is like the proper mathematicians programming space because it
does symbolic math, right? Which is so remarkable when you see it go. Yeah. Like that was basically
like I could visualize. The thing was being able to do easy visualizations. So actually after undergrad,
I worked at Mathematica for a while on their visualizations team.
Yeah. What technologies was that in?
I was actually just writing Mathematica in Mathematica. Thankfully I didn't have to touch
any of the optimization stuff underneath, but designing new like gauges and plotting built-ins
and stuff like that. I really enjoy visualizing and understanding data that way. And so when I got
to grad school, realized that none of our instruments talked together. Like everything was an entirely
separate archaic non-documented protocol and we were having to somehow like either sit by hand and match
up all of these CSV dumps from the different tools and stuff like that. So basically I started learning
Python to make our lab work. So initially it was like using a serial and C types libraries to actually
interface with these APIs. But I realized someone once showed me a Jupyter notebooks and I was like,
Okay. This is how we're, this is the way.
This is Mathematica for Python.
Exactly. So I have been using Jupyter notebooks almost since they came out and really enjoyed that
both as a learning tool, a teaching tool, and a kind of reproducible science tool.
Yeah. It's just taken the world by storm. Really. They were here at Microsoft Ignite,
the keynote, they went, they had like basically one code oriented demo in the two and a half hour
our keynote. And it was now we have a Jupyter notebook with some Python code that's going to
do some machine learning and you know, back to cats and dogs.
Yeah. Yeah. Yeah. Yeah.
That's incredible. So yeah, very cool. These days, what are you doing?
I am a developer advocate at Microsoft on the Python team focusing on data science and machine learning
sorts of Python tools. So I get to, I get to do all the fun stuff with pandas, numpy,
scipy, all of those things. And that's kind of why when I heard about the Python and Excel preview,
I was like, Oh, I have done many pandas import from Excel sort of things and was kind of curious
to see. Cause initially I was like, Hmm, I'm pretty cool with my Python. I'm not sure why I want to go
that way, but suffice it to say, I think I I'm convinced now.
Are you? Okay. Yeah.
Yeah. Because it's kind of a different way than a Jupyter notebook. It's for pluses and minus. We'll
talk about some fun ones of those as we go. Who are you evangelizing Python on the behalf of Microsoft
too? So are you talking to like companies that do .NET saying, Hey, you should do Python. Are you talking to
companies that love Python and saying like, Hey, you should consider Azure or our, our offering? What
does your world look like? What do you do today?
Yeah. A lot of it is doing testing. I work a lot with the VS Code team and the Jupyter specifically,
like the Jupyter features in VS Code to make sure all the notebooks work to make sure, you know,
packages with kind of weird output visualizations, you know, are they rendering properly? Generally,
I think I work with a lot of the actual Python open source maintainer communities in the kind of scientific
Python space. So like with the num focus supported projects and really just try to kind of understand
what are they running into? And as we're definitely seeing both with all of the LLM and machine learning
stuff, like data is getting so big that I definitely can't open it in one Excel sheet. And so the data is,
you know, basically, we're to the it's all native on the cloud. And so there's, I think, a lot of
kind of the academic space that I'm, I come from of like, that isn't really part of the curriculum or
what's taught or, you know, people kind of have to learn it ad hoc. And so basically, I kind of like
to think of myself as someone who gets to go do all that learning about kind of how does science and
data interact with the cloud, and in this case, specifically Azure, and just try and help build
out scenarios, like build sample apps, things like that, that can make it so they don't have to waste
half their PhD time trying to understand cloud DevOps stuff.
Yeah, it sounds a little bit like, you know, a lot of people who are just brought into a lab and said,
here, you're going to learn Python, and then you can go do your, your actual research, they often sort of
skimp out on like, some of the very basic software practices, like what is Git? What is DevOps? How do I run
this? Like, yeah, those kinds of things, right? So maybe you've run a lot of workshops, like, have you?
Basically, in my postdocs, I got really tired of my teams and groups that I was working with not
knowing. So I basically made a standard two day workshop that was like, all of the computer science
skills you missed in your physics degree. We did have at one point data that just existed only on
a jump drive, and that jump drive walked away. And that does not feel super good from a research
standpoint. I can imagine.
Yeah, let's just say we, we had a review of that and instituted new policies.
We decided backups are good.
Yep.
Yeah, it's a bit of a divergent, but I worked on some math research before I graduated and got my
bachelor's. And it wasn't, it was just in C++, but we had these large silicon graphics computers,
like big mainframe thing. We had, you know, Onyx workstations that went into it. We came in one morning
and nobody could log in. The computers wouldn't respond or turn on us. It's like a quarter million
dollar computer that got used and it won't turn on. We're like, oh boy. What had happened is one of
the grad students, non developer types, just doing their research, had a problem with their program.
So they started logging to see what was going on and they left it running overnight. It filled the disk
to the very last bite. And apparently once the last bite was gone, the whole mainframe couldn't,
operate and just nobody could even figure out what was wrong with it forever. And eventually,
yeah. So, you know, practices.
Yeah. We also had a $5 million microscope get bricked because a younger grad student didn't
understand that Windows XP service pack zero should never be plugged into the internet.
Oh, so no firewall, none of that.
Oh, no, no, no, no. They were just like, well, it has an ethernet port and the company said they can,
you know, do support over TeamViewer or something like that.
Yeah. So they were like, yeah.
A TeamViewer. That's never going to go wrong.
Yeah. So we walked in and we had to yank it out of the wall and we had the police there the next day
because it had already been doing illegal financial transactions in about 30 seconds.
Wow. You mean a microscope. You're here to arrest a microscope.
Yeah. I was like, it's over there.
They're like, well, that's not a computer. It already is. All right. Another interesting thing
before we dive into our main topic here is I'm not sure if this is real or not. Did it happen or did
it not? This quantum work that you're doing? Yeah. So my PhD was on quantum cryptography
hardware. So both there exist commercial devices. So part of it was finding side channels and the
physical devices that you could buy off the shelf. And then the other part was designing satellite
optics for doing ground to satellite based key exchange. So, yeah, that was a lot of what I was
doing in the like prototyping things in the lab that would look like a satellite and we'd,
you know, satellite on one table, sender on the other. And we slowly worked out to,
we did a bunch of tests in an airplane because turns out like putting things on a satellite is
kind of expensive. And we just flew really high in a 747. Yeah. And weather balloons turn out to be
not super predictable in the path once you launch them. And so if you're trying to like aim telescopes,
yeah, it kind of ended up being messy, but it was pretty cool. We got to go,
I got to help with the design process for these single photon kind of collection systems that went
from literally, I'm just putting a couple lenses on the table and running Python stepper motor things in
my Jupyter notebook to something that was actually automatically tracking and working from the ground
to an airplane, hopefully eventually a satellite, but that's kind of out of my hands at this point.
Yeah. Space takes a long time to get to a lot of planning and a lot of, we worked on it for
eight years and then we had our launch window missed by a week, you know, or something like that. Right?
Yeah, that's rough. And as a grad student, you got to get out of there.
Yeah. I got to get a degree. I need to eat.
Yeah.
So let's get, let's get going. Cool. Well, that sounds like a really fun project. You must have
learned a lot. And whenever you're talking to hardware, I think that's a special kind of programming.
It's not just, I run the program and then it just goes, but like there's stuff it touches.
Yeah. Like you don't get to necessarily do your own architectural design. You have to kind of
first observe and usually reverse engineer what the original device engineers came up with and then
figure out how is this, you know, this device is streaming base. This device, how am I going to like,
these are entirely different, like application models.
You really chose the serial port. Okay. All right, then let's go with that. Cool. All right. Now,
before we get into Excel in Python, let's maybe talk about working with Excel from Python, like the
reverse, right? So you talked a lot about notebooks and many people go from kind of notebook into CSV,
into Excel. And there's some common tools for doing that. Like even built into Pandas, for example,
could be Wilson's what they can do there before they have to necessarily decide, like,
I need to run it in inside of Excel. I think there's still a special value to having structured code.
Oh yeah, for sure.
That you could have. I mean, notebooks is like kind of a fuzzy structured code. It's not like,
it's not like a proper PY file because you can run the stuff still out of order, but at least within
the cell, it runs within order. You know, it's like one dimensional out of order rather than like Excel,
Excel, which is two dimensional potentially, or three if you're taking to other workbooks. But
anyway, what can people do if they're not just to talk to Excel now?
Right. I think you kind of alluded to it, but the main way there are a couple of packages.
One is actually built into Pandas, but I think it's a dependency on OpenPy Excel. But yeah, that basically,
I've been playing around with that recently to try and see if I can get support for the
new Python based cells in that parser. It turns out parsing XML is not fun and not something I like
doing. But basically-
I've spent the last two days parsing Excel or XML. Oh my gosh, it's not the funnest.
And in particular, you know, standardized document specs, because that's basically,
so there are wonderful packages out there already that do this for you. And so what you would do is
you'd basically just hand your Excel file, CSV, whatever to these packages, and they would
return them as basically whatever you like. Usually I go to Pandas tables because there are data frames,
because why not? But yeah, so there's basically any format that you could pretty much want. There's
probably already really nice tooling to import that. And you can just go right on your merry way using
your Python. Yeah, you can use the XLSX writer if you want to create Excel. Yeah, yeah, yeah.
Right? Like-
Yeah, it's really cool. You can even like make plots. You can, from Python, make a plot in the Excel
worksheet so that when somebody opens it, they see the plot made in Excel. Kind of crazy.
This portion of Talk Python to Me is brought to you by Posit, the makers of Shiny, formerly RStudio,
and especially Shiny for Python. Let me ask you a question. Are you building awesome things? Of
course you are. You're a developer or data scientist. That's what we do. And you should check out Posit
Connect. Posit Connect is a way for you to publish, share, and deploy all the data products that you're
building using Python. People ask me the same question all the time. Michael, I have some cool data
science project or notebook that I built. How do I share it with my users, stakeholders, teammates?
Do I need to learn FastAPI or Flask or maybe Vue or ReactJS? Hold on now. Those are cool technologies,
and I'm sure you'd benefit from them, but maybe stay focused on the data project. Let Posit Connect
handle that side of things. With Posit Connect, you can rapidly and securely deploy the things you build
in Python. Streamlit, Dash, Shiny, Bokeh, FastAPI, Flask, Quarto, ports, dashboards,
and APIs. Posit Connect supports all of them. And Posit Connect comes with all the bells and
whistles to satisfy IT and other enterprise requirements. Make deployment the easiest
step in your workflow with Posit Connect. For a limited time, you can try Posit Connect for free
for three months by going to talkpython.fm/posit. That's talkpython.fm/posit. The link is in your
podcast player show notes. Thank you to the team at Posit for supporting Talk Python.
That's been around for a long time. That's not like an announcement or anything.
Yeah, yeah, yeah.
There's been different ways, and they've come in and out of support for different Python versions and stuff.
So, but there are ways to kind of do that. And I see that a lot of people are like, I'm working in
notebooks, but the final consumer of this information is not a data scientist or a Python person. They
live in Excel and they live in Outlook. The only thing I can give them is Excel spreadsheets or a PDF.
Yep. That is pretty much always the output of my notebooks is I either export it, like the whole
notebook as a PDF or yeah, basically organizing things such that I can use Pandas or something to
export it to an Excel workbook. But it's kind of a pain then because like you have your, there's that
translation step that you kind of have to keep going back and forth. If you're dialoguing, you know,
somebody says, oh, but what happens if you do this? And it's like, okay, I got to go rerun and remake a
new PDF for you. Could you just like do it?
I just need a quick change. Like, could you just incorporate that? Like, yeah, it's not the same change.
We got to read.
Ideally, we all have nice DevOps pipelines where, you know, you just commit a change to source and it
re-renders all the notebooks. That's in a perfect world.
Of course, that's how it works.
Yes, obviously that's how I always work.
It is. So I guess, you know, before we get in the details of how this works, like, why?
Right. Because we just laid out, it is possible to like go to notebooks, have Excel kind of as an
output and a save as in a sense.
The biggest thing for me is like, well, it's not intended, of course, as any sort of replacement.
It really is, as you were kind of mentioning before, it's like a different front end sort
of thing. Like we view there's Python scripts, there's Jupyter notebooks, which is kind of like
an alternative front end for writing that Python code. I kind of think of using Excel and Python
like this as kind of using a different kind of data first. Like whenever we're thinking about data,
it's usually in some form of grid or table or something like that. So like being able to work
with the data kind of visually in that sort of UI is really, really interesting and kind of to the
point that you just made about like the end consumer might only know how to use Excel and
doesn't know anything about Python or doesn't know anything about running DevOps pipeline.
I didn't mean that comment either to be disparaging because there are people that do incredible stuff
with Excel. Maybe they shouldn't, but they can and they do.
I have in kind of delving trying to understand what are like the weirdest things Excel can do as I've been
trying to make demos like people do some weird like competitions with Excel. Like there's the painting
in Excel.
Is there a flight simulator?
There's flight simulator. Like you can, you know, with macros, it's very scary. So I, yeah,
absolutely. Like I am, I am not an Excel pro. I am a Python developer who uses Excel when prompted.
Yeah. Well, there's no question. Absolutely. No debate about it, that the upper bound of what
you can do with Python is greater than the upper bound of what you can do with Excel. But so many
people just have, they have tabular data and they need reports and understanding and change this,
what happens there. And yeah.
Yeah. And I, and I think the biggest value, like kind of having played with this now for
a little over half a year is collaboration. You don't have that kind of, you don't have to
have to have that iteration loop between, okay, here we talked about it, or, you know,
you came and sat at my computer while I showed you, you know, my Jupyter notebook. So we can make
changes like that. All of the things like having multiple people in the Excel doc at once, you know,
you can just send the share link and they can join and they can run things in the notebook. They don't
have to install or set up Python and you can just, you can leave comments like you would in Word docs.
So like basically that whole kind of review and collaboration workflow just turns into something
that people are already pretty familiar with, with like Word docs and stuff like that, which is a
thing that Jupyter notebooks generally don't have. So I think that's kind of the, one of the most
interesting differentiators between them.
Yeah. I just like an hour and a half ago, released the episode on notebook seven and Jupyter
lab four, which comes with the real time collaboration and stuff.
Yes. Which is really exciting.
Yeah. It's quite exciting. So it's, it's on the horizon.
Yeah.
If it hasn't been like a common thing, but even so again, a lot of these people are not going to be in
the notebook to collaborate with you.
Right. Right.
It's fine. And you played with this for a while. How much of this is going to be a gateway experience
to doing more like, ah, I couldn't remember that Excel formula, but I asked Copilot and it told me
me to do this Python thing and I, it totally made more sense to me. Maybe I should just learn a
little more Python and, and kind of grow beyond Excel. Like, what do you think of this as a,
a first step for many people who would go, I'm not a programmer, which no way, I'm not a geek. No,
but then they are.
Yeah, they totally are. Like if you're playing around with a bunch of numbers and making fancy
spreadsheets and stuff, I'm sorry, you're, you're nerdy about data. And so, yeah, I think it's a really,
cause there are lots of really cool things you can do with Excel. But as you say,
like some of the plotting features and stuff you can't do, like you can maybe do, but it'd be really
hard. And some, it might just be straight up impossible to make, you know, like some of the
matplotlib multi-paneled, aligned plots with like interesting statistical plotting things that aren't
just your standard bar and chart sorts of stuff. So like, if you're trying to do some of those
statistical modeling things, or the, the other big thing is like the Python and Excel, one of the,
it has PyTorch and stuff like that. So if you want to do just kind of like entry level machine
learning sorts of stuff, and you don't want to have to like set up your big data source and SQL servers,
you know, whatever, what have you to work with it. If you just got your spreadsheet of like your home
sensor data or something like that, you can actually just have it make a regression model.
And you don't have to like spin up a whole thing, you know, and environments and stuff like that.
When you predict the battery in your gate will be dead next week, you're going to need to take an
action on this.
Which will be great when then I dismiss the notification and still don't remember to do
it.
Why can't we leave the house? Well, remember that notification said you're not going to be able
to open the gate in a week. That was a week ago.
Mm.
Mm. Sounds familiar.
Yeah.
I know we were talking earlier that you have some cool home assistant automation and stuff.
Yeah, yeah, yeah.
So.
Awesome. And I have a gate that has a dead battery.
So let's just jump into it. I mean, let's talk about what is Python in Excel? Like,
how do people use it? What can it do? What can it do?
In short, basically having the Python in Excel feature means that you can, when you're in a
cell, if you type the equal sign, which is usually how you start a function in Excel.
Right. You might type equal sum parenthesis and then off you go. Something like that.
Exactly.
Drag it around.
So you type equals and then you type PY, open parentheses, and that basically turns the
cell now into a Python cell. So it'll have a little visual change. It'll turn green on the left.
And there's also a keyboard shortcut to do this.
It should put the Python logo. It should be like a blue, yellow.
You know? Come on.
Yeah. Green is kind of the Excel color.
Yeah, it turns green.
I don't know.
It turns green.
Anyway, we can file feedback on this.
Yeah, well, that's community feedback from the Python people. We need the Python logo in there.
Let's make it happen.
The idea is that basically you can change a cell in the Excel notebook into one that basically
is kind of like a Jupyter cell. You can type Python code. You can import modules. You can write functions.
You can print things like basically anything that would be valid in a Jupyter notebook cell. Maybe
not necessarily the magic commands, but like...
Sure.
It's fair game.
Get to the shell as a hacker, I just do.
I did actually try a lot of that. So I should say, so once you've typed in your code there and
you run the cell with Ctrl+Enter, it's not Shift+Enter because that's a very established keyboard shortcut in Excel,
which moves you around in the grid. So pro tip, remember it's Ctrl+Enter. But what happens then is
basically Excel connects to a container instance in Azure and which has a standardized Anaconda provided
environment. So it's an Anaconda environment that has a fixed declarative set of packages, which is
basically kind of what 80 to 90% of projects use. We can talk about like which ones that are that,
which ones are in that environment in a second. Yeah.
But your code then runs in this, you know, it referred to as like an iron box in this container instance.
So it does not...
It doesn't know who you are.
It doesn't know who you... Well, I mean, you are... And it's basically running a Jupyter kernel in that box.
Right, okay.
So like the kind of communication, if you have multiple cells in your sheet that have Python code in it,
every time you make a change, you know, just like an Excel would normally kind of like recalculate
everything in the sheet, it will basically ping that iron box and as if it was kind of like a Jupyter notebook.
That's the thing that surprised me most is that it doesn't just run locally because you could embed the Python runtime
into Excel without any trouble.
Yes.
And in terms of making the good path work.
Yes.
But I think part of the, you know, part of the design philosophy with this as a feature
to Excel is this is an enterprise product that enterprises want to use and IT admins want to feel good about,
you know, what security permissions things, you know, where data can come from,
like all the permissioning compliance good stuff.
You don't want to see so...
To go, it does what?
Yeah, no.
No, we're not doing that.
And we just recovered from the ransomware thing.
So we're definitely not, we're done.
So what are the restrictions?
It has no network access.
Yeah.
So that iron box does not talk to, the only thing it can talk to is your, you know,
instance of Excel.
It can receive commands, but it doesn't.
It does not touch the internet otherwise.
Interesting.
So that automatically changes maybe what some people think, like, for example, pandas read
CSV, give it a URL and say, I want the third table.
Like it's not going to do those types of things.
Or you can't do request.get against some external data.
Mm-hmm.
Which initially I was like really sad about.
I understand the security things, but was a bit sad.
But then some of my Excel friends showed me, because this is also kind of a challenge in
Excel too.
Like, you know, how do you get data?
People have things in SQL servers, people are databases more generally.
Data that updates every minute.
I want to have it refreshed.
Yeah.
Like that kind of, it's not concurrency, but like keeping everything up to date is a really
big headache.
And the thing is, Excel is already very good at addressing this.
So there's something called Power Query, which is another feature of Excel.
And that's basically, so the scenarios like you described, like if there's a CSV somewhere
in a GitHub repo that I want to pull in, you can use the Power Query feature, can go fetch
that and bring that into your Excel file that then you can use with Python and Excel.
Okay.
So it kind of separates that task of getting the data to work with, kind of prize that out
of the Python piece, but puts it in much safer hands.
Sure.
So secure hands, I guess, if that makes sense.
Yeah.
Restricted hands.
Mm-hmm.
Okay.
It doesn't have access to your account.
It doesn't have a token to your account, like your Office 365 or whatever.
Yeah.
It's pretty locked down.
You can't pip install things.
It comes free, free can.
Yeah.
It does what it says on the tin and like, okay, these are the things I can do.
Yeah.
And that, again, sounds kind of sad, but honestly, like I've been trying to make a bunch of samples
and stuff and I haven't run into too many, like it's got numpy, pandas, scipy, seaborne,
astropy.
Yeah.
Astropy is pretty awesome.
It's got matplotlib, pytorch, as you said, pywavelets.
How's that for a throwback to my mathematical days?
That's some like fast forward transforms are way more complicated.
Mm-hmm.
scikit-learn, scipy, simpy.
Yep.
There's your matlab, right?
Or your mathematical right there.
And yeah.
And others, right?
I'll link to like the options.
Mm-hmm.
This portion of Talk Python to Me is brought to you by the Pybytes Python Developer Mindset
Program.
It's run by my two friends and frequent guests, Bob Belderbos and Julian Sequira.
And instead of me telling you about it, let's hear them describe their program.
2024 is unfolding and with it comes a world of opportunities in the Python landscape.
Opportunities for your Python career and journey can come from anywhere and at any time.
Are you ready to seize them when they do?
Don't let this be the year when opportunities pass you by.
Our Python coaching is designed to prepare you for the unexpected, to equip you with the skills and
confidence needed to tackle any Python challenge. Whether it's a dream job, a complex project,
or a new venture, you need to be ready for it.
With Pybytes coaching, 2024 won't just be another year. Check out our PDM program and take the first step towards a year filled with Python success.
Don't just dream about being a developer. Achieve it with Pybytes.
Apply for the Python developer mindset today. It's quick and free to apply. The link is in your podcast player show notes. Thanks to Pybytes for sponsoring the show.
Yeah. So yeah, like it really does cover most of like, obviously, there are still plenty of cases where you will just want to use Python and that's okay. Like that's this is in no way, shape or form is this supposed to like take over your entire Python workflow. It's really,
you know, I still am doing my Python development. But basically, if there are people who I know I want to,
like, especially communicate what I'm doing to like who that is their language, I now have a tool that I can kind of put the things that I would normally have in my development environment in a tool that they can access and interact with, too.
So that, you know, also doesn't feel super bad to me.
Well, what's the alternative? It's the right like Excel functions and VBA macros.
Yeah, no, I'm not doing that.
Yeah, it's a pretty massive upgrade. And I do think it's going to be a bit of a gateway like, you know what, this Python stuff's not that complicated. It's kind of cool. Maybe what do you do with those notebooks again?
I think that'll be cool. Yeah, it'll happen. When I think about writing Python, I'll use something like PyCharm with like really cool code, like analysis. And then I'll think about it like with rough, maybe running as like an integration and autocomplete. And there might even be like an AI magic, or maybe this is happening in VS Code in a real similar way.
Then when I think about writing Excel formulas, it's like one line across. These are not the same. So what is it like to write Python in Excel?
Yeah, it definitely. I do generally try to keep like when I write note, like in Jupyter notebooks, I try to keep myself small, not just have giant things. But yeah, you're totally right. Like even just from the view, you can't really drag it much bigger than a couple lines.
You can expand it. So it's at least multi line.
Yeah, you can you can see multi line and that and that's fine. And it has syntax highlighting and it does have like tab completes. It's got like the do like the language server language server.
Yeah, that's actually pretty good.
As I think was in the keynote stuff today, there's copilot in Excel. And so like, we'll see, I think, some of these AI features also kind of help speed up some of those things. So like, if you're like, I just I want a pandas table here. And, you know, to convert this part of, you know, the diction, the column, that's all dictionaries to like their own columns and stuff like that.
It'll just write it for you. And you don't have to that editor editing experience is definitely not the same as you know, working in my beloved VS Code.
But well, if the keynote here at this conference was a drinking game and AI was a word, it wouldn't have lasted 15 minutes. And it was two and a half hour. I mean, there was so much AI this and AI that and the AI is talking to the AI is and here's and it's it's quite something.
But they did show a really cool thing of like, I've got some Python code in here and I've got some some related data and just asking like, all right, help me graph this in Python.
And it would show you like a seaborne graph or matplotlib or something like that, which is pretty excellent, honestly.
Yeah. And then in this case here, then it would be in a format that you could share with somebody that they could then Excel has what if scenario features where it makes it really easy to be like, well, you know, here's the forecast or whatever.
But what if this change?
What if interest rates go up?
Yeah.
And you have like these little dropdowns, like all of those actually work.
And so like I can use cells that are like dropdown data validated dropdown cells.
And that just feeds as feeds into my Python code and changes, you know, like the theme I'm using for my matplotlib plots or something like that.
Go a little meta for a moment.
Could I use pandas or XLXLX writer, whatever the extension is to write an Excel workbook, Reggie, that itself does has Python in it?
In principle, yes.
Are there just formulas?
Are there just strings that go into formulas?
Yes.
And that's precisely what I've been working on recently is to try and figure out how to integrate into some of those, the existing Python packages.
Because basically what you need to do is make sure all of that data is inserted into the XML document model in the right way and stuff.
Like it's pretty cool.
Like you can take it.
You can take an Excel, you know, an Excel notebook.
If you just change extension to zip, then you get to see all the XML that's inside of it.
And you can just see.
A red pill.
You can just see the sheets that are like, here's the Python functions and you can just see the strings and stuff like that.
So I don't think there's anything blocking that.
And that's something that I want to be able to help contribute if I can to the community so that you could actually programmatically write your Excel sheet with Python from Python.
Right.
And so things that are not allowed, like screen scraping or talking to a database, you could kind of burn that into Excel as like fixed database and keep rebuilding that workbook or something like that.
Yeah, you could do that.
All right.
Integration between Excel and Python.
In Excel, I can say I want to take the sum and I select the big section and it's like a 1 colon a 20 and that sums those up.
But in Python, data science land, I don't even know what that is.
So how do I make, obviously the point of having Python there is to access chunks of data, process it, do other things to it, turn it into graphs.
What's the interop story?
Part of the Python and Excel feature is that in that content environment, there is a module called Excel.
The abbreviation as it's loaded is X, the letter X and then the letter L.
And basically that allows you to access all kinds of data and properties of the worksheet in Python.
So that's basically, you know, whether anything from like the cell styling to you can literally just put XL parentheses and then in a string, the Excel selection, you know, A1 colon whatever selections.
And it will just then is already available in Python.
So there's kind of this interop package that allows you to transition data models between what Excel thinks of as data and what Python thinks of as data.
Yeah.
And basically that comes out as a Pandas data frame, right?
Yeah.
In general, once you run a Python or a Python, an Excel cell that has Python code in it, you run it.
There's a lot of cells, sheets, code.
After you run it, you have the option of two different output formats, actually.
So you can, by default, I think it outputs as a Python object.
Yeah.
If it recognizes that it's a string or a list, it might just display that.
Or you can kind of intentionally cast it to an Excel data type.
And again, if it can automagically understand that, oh, this dictionary should just be in a list or something like that.
And a lot of that functionality is kind of provided by the collaboration with Anaconda.
So you'll see, like, if you hover over, if you have it return, like, a Python object, if you hover over it, it'll show you, like, you know, if it's a class, it might have some show you the properties.
And then you could drill in and say, turn, you know, turn the output into displaying this property.
But it shows you a little pop up with the Anaconda logo.
Yeah, that's some interesting branding there.
I did notice that as well.
In Jupyter, I can have a cell, and I can say, like, X equals something.
And then some other point in time, I can say X squared, whatever.
That assumes I'm running them top to bottom, or at least those two cells, the one that defines the X is run before the one that uses the X, which makes notebooks a little bit non-deterministic.
And if you don't just go run all cells, but Excel takes it to a whole nother level, right?
This refers to that, which points over there, and then that goes up, and then it goes back down, and it's all over.
How do we make sense of, like, the connections?
Yeah, it is something that I've, like, always is very impressive about Excel, because I'll, like, copy and paste chunks of things, and somehow all the references stay correct.
You know, like, that's not what would happen if I refactored my Python code.
By default, the execution order goes left to right and then down.
So that's something I got to, I generally just kind of, by convention, use single columns.
We're just going down.
And left to right on the number of worksheets.
So it evaluates everything in the first, like, if you have tabs at the bottom for separate sheets.
Yeah, you can go cross sheet as well.
Oh, yeah, yeah.
And so, like, honestly, one of the things, kind of habits I've developed working with this is the first sheet in, like, the top left corner, I put any sort of, like, inits or things that, like, things I want to have defined everywhere.
I just put in literally the first cell that I could ever possibly evaluate.
And then everything else from there will be what it's going to be.
But that's how I make sure those things.
And actually, when it spins up, there is a predefined kind of startup definition block.
So it will automatically import pandas as PD, numpy as NP.
Like, so you don't have to, like, a lot of that kind of standard boilerplate, you don't have to.
But if I'm doing a notebook where I'm doing a lot of.
Like scikit learners.
Yeah, yeah.
I just always want to have that there.
I just got to copy pasta for that.
Yeah, make an incredibly thin column.
That's the viewer to expand it.
Yeah.
That's where you're right.
That's actually, I've done that.
Yeah.
Awesome.
But just like in a Jupyter notebook, though, that kernel, like, if you can define variables like that X, and you can use that anywhere else, and then you can also just put it in a cell, and you can have Excel refer to it.
And it will also know what data is there.
Right.
You might have to do the Py or the XL to, like, transform it.
Yeah, yeah, yeah.
Otherwise, then you just use it.
Yeah.
Awesome.
So you said this runs in Azure, and it's some lockdown container.
But what version of Python?
Like, what OS is the container running?
What's the story?
What do you know about where this actually runs?
Or, like, to the extent that people will care?
Yeah, yeah.
So I don't know the specific version.
I'm guessing it's probably 3.11.
But the idea is that it is a well-known and highly descriptive and fixed container description.
It's running, I believe it's just kind of running on a standard Ubuntu, like, Docker.
It's an Azure container service.
Somebody could do a sys.platform and get that and get it out, right?
Interestingly, yeah, you can try some of that.
But how they've kind of helped lock down some of that is there's actually hooks.
Because I was actually trying to do this.
I was trying to exfiltrate and or escape the box.
But they actually...
Can't contain me.
They have hooks in the Python interpreter that basically can catch anything before it touches anything outside of Python.
And so it's, I mean, I am not a security expert.
I am not a security expert.
But any, like, naive sort of, like, ha, ha, ha, I'm going to import sys and, like, manipulate permissions.
Yeah.
OS.run.
Yeah.
Open pip install.
Exactly.
So all of that is pretty safe.
Yeah.
It's going to be, you know, a modern version of Python.
It's going to have everything up to date.
And from a supply chain standpoint, it's all provided by Anaconda, which they have assertions
about code origin and stuff like that.
So really, it should be a reprodu...
The most best definition of a reproducible environment that will literally...
So, like, even in perpetuity, like, if you hand the worksheet to somebody else and you 10 years later come back to it, assuming, you know, the earth hasn't blown up, presumably it'll run in a container of exactly the same description.
So you don't have to worry about, oh, shoot, I wrote this in a version of Python that now the package was built with Python 2.7.
Can you believe I wrote it in Python 3?
Yeah.
It's just like, we're in Python 14.
It doesn't work.
And so many things are still in 2.7.
Yeah, I know.
It's wrong.
Yeah.
Like, so the statement that I saw and sort of the stability says, existing workbooks will still calculate against the version of the environment the workbook was created on.
And users can be prompted to upgrade if they want, like, new runtimes, new Python versions or whatever.
So basically, there's no requirements.txt or pyproject.tom all pin in your versions.
But at the time of creation, it kind of snapshots effectively a pinned virtual environment.
Yeah.
And as I mentioned, there is kind of like a fixed startup script for it that does those kind of suggested imports and, you know, settings for things, which you can actually view in Excel.
It shows you and it's read only right now.
But we that might be a thing that you might be able to edit at the beginning.
So if, you know, there are the things in that one cell that I always put at the beginning, maybe I can change that for my notebooks, sorts of things.
Yeah.
So it's still in preview.
It's not.
If I go to my Excel that I've got installed on my Mac and just try to type this, it's not going to like it.
It's not going to work.
Okay.
How do you get it?
Yes.
So right now you it's in the Windows Insider program.
So you have to have a M365 sort of subscription for Excel.
You have to enroll in the Insiders program, which you can do if you go to your account settings in the app.
Right now, like because it is a gradual rollout, I think the initial public preview was only in September.
Yeah, it's pretty new.
Yeah, it's it's quite new, like pretty much every week when I start working on this, I'm like, all right, what, you know, does this look the same as it did last week?
So but right now it's only available for Windows machines.
It is fully intended to be available on all platforms, including the web based version, which will be super cool.
Yeah.
But yeah, right now, Windows initially and the feature itself is will have some sort of cost, what that is and how much and when is TBD.
Just because this is a very good.
Is it extra?
Who knows?
Yeah, exactly.
Yeah.
Awesome.
Well, really cool to get a look at this.
I think for me personally, I think the coolest thing about it is that it's going to expose more people to Python, give them a little bit of confidence and then they can go only 20 libraries.
I heard, oh, over on PyPI.org, we're just under 500,000.
Maybe I could expand my world of it, right?
That's awesome.
Yeah.
And you don't have to like, all right, download a version of Python now or download a version of Anaconda.
Now make sure you have all the things installed.
Make sure you have permissions, things on path, like all of that just goes away.
Create a virtual environment, activate it.
Yeah, all this stuff.
Yeah.
It's just already handled for you.
You can get right to the fun stuff.
Yeah, that's super cool.
All right.
Well, I always ask at the end of the show for some PyPI package that you think is cool.
You've come across like anything that you're like, oh, that's interesting.
People should know about.
It doesn't have to be popular.
Oh, no, no, no.
There's one I can't think of the name generates a bunch of fake data for you to use.
Okay.
There's, is it, Makaroo?
And Makaroo is the website.
Yeah.
And there's Faker.
Faker is good, but it's like hypothesis.
Okay.
Come up with a different one, though.
Well, one that is near and dear to my heart is actually called PyQIR.
Okay.
So one of the, I mentioned the quantum computing stuff before.
One of the open source communities I'm still really engaged with is actually an open source
consortium to basically create a LLVM style machine agnostic, language agnostic representation
for quantum programs.
Wow.
Okay.
Which is really cool.
And like coming most of programming right now has kind of was born in Python.
Like Python was the host for all of this, but as it's growing up and, you know, kind of leaving
the nest as it were from Python, basically we need ways to interrupt like this huge existing
tool ecosystem with actual hardware and hardware that supports things that basically the Python
like mental model doesn't really match up.
Like, and that's why you kind of need domain specific languages for quantum computing.
But this PyQIR package gives you kind of an easy way to connect and like, like bootstrap
that interop from your quantum programs that you've written in Python to this intermediate
representation, QIR, quantum intermediate representation, which is actually LLVM.
So you can, you don't have to figure out how to write and export LLVM files, which is both
very fun and informative and you can do it through Python and Rust.
The PyO3 Rust crate is my favorite.
Yeah.
So that's, if you're at all interested in quantum computing stuff and you have a Python
skill set or interest, that would definitely be a package I'd say go check out.
Excellent.
All right.
Well, final call to action.
People want to get started with this stuff.
What do they do?
Yeah, definitely.
There is a great blog post with the original announcement that's got all of the detailed
steps for how you find and enroll in the insiders programs.
But other than that, there is a GitHub repo.
If you do get a chance to play with this and find all the things that you hate about it and
want to come yell at people about, I field a lot of those questions and enjoy it.
So yeah, you can just come file issues on the GitHub repo and, you know, like if something
isn't working the way you thought or you find a bug, that's kind of the best way that the
team is very active.
And so that's a great way to kind of get some good interaction with the folks who are building
this in real time.
Very cool.
All right.
Well, Sarah, thanks for being here.
Yeah, absolutely.
Thanks so much for having me.
Yeah, you bet.
Cheers.
This has been another episode of Talk Python to Me.
Thank you to our sponsors.
Be sure to check out what they're offering.
It really helps support the show.
This episode is sponsored by Posit Connect from the makers of Shiny.
Publish, share, and deploy all of your data projects that you're creating using Python.
Dreamlet, Dash, Shiny, Bokeh, FastAPI, Flask, Quarto, Reports, Dashboards, and APIs.
Posit Connect supports all of them.
Try Posit Connect for free by going to talkpython.fm/Posit, P-O-S-I-T.
Are you ready to level up your Python career?
And could you use a little bit of personal and individualized guidance to do so?
Check out the PyBytes Python Developer Mindset program.
Want to level up your Python?
We have one of the largest catalogs of Python video courses over at Talk Python.
Our content ranges from true beginners to deeply advanced topics like memory and async.
And best of all, there's not a subscription in sight.
Check it out for yourself at training.talkpython.fm.
Be sure to subscribe to the show.
Open your favorite podcast app and search for Python.
We should be right at the top.
You can also find the iTunes feed at /itunes, the Google Play feed at /play,
and the direct RSS feed at /rss on talkpython.fm.
We're live streaming most of our recordings these days.
If you want to be part of the show and have your comments featured on the air,
be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
This is your host, Michael Kennedy.
Thanks so much for listening.
I really appreciate it.
Now get out there and write some Python code.
Bye.
you
Thank you.