r/learnpython • • Apr 13 '22

What is difficult in excel but easy in Python?

If you were to introduce an established excel user [non VBA] to Python, what would you suggest?

What would amaze them? In as few a lines as possible?

404 Upvotes

241 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Apr 13 '22

[deleted]

29

u/unhott Apr 13 '22

I’m sure there are some libraries that can change your mind.

https://seaborn.pydata.org/examples/index.html

0

u/[deleted] Apr 13 '22

[deleted]

24

u/[deleted] Apr 13 '22

matplotlib is like pulling teeth. Eventually, the pain goes away, but it wasn't fun getting there.

Seaborn is amazing. The moment you move away from trivial data that you can basically copy and paste in, python + seaborn is easier than VBA + Excel.

28

u/SirGeremiah Apr 13 '22

I doubt it. They didn’t say graphs were better in XL - just easier. And they are. I can knock out an Excel graph from reasonable data in just a few clicks. No matter how good I get at Python, it’ll never be easier for simple, basic charts.

3

u/angry_mr_potato_head Apr 13 '22

df.plot()

8

u/hmiemad Apr 13 '22

Yeah but pivot table + graph is so handy, just drag and drop fields, add filters, one or two intermediate fields, post grouping fields, group per mean, std, sum, any basic stuff. Plus any desk job can open an excel and click a macro button to load a csv and crunch your data into a nice graph that you can copy and paste as an image into a ppt or email.

Of course the power of python is huge, but it comes with knowing how to code. In one week one can learn to make nice pivot graphs, if you know a little math. How long does it take to learn to make an interactive graph with python? Months ! Years if have never coded.

Everything in Excel is visible, every step, every formula, it's user friendy. Link access and PowerBI to create a centralized data lake with dashboards. It's seriously insane how much it can automatically structurate you data.

I won't ever code in VB, hopefully, now that I know python, but I miss the handiness of pivot graphs a lot.

1

u/Ikwieanders Apr 13 '22

With seaborn it kinda is though right? I only use Excel every now and then though, so ofcourse I am not very fast in Excel as well. But still, simple chart in Python takes a few seconds of you have a dataframe.

3

u/SirGeremiah Apr 13 '22

I’d have to see that to understand. I only see Python as a programming language, so the idea of a chart being as easy as a few clicks is like magic to me.

3

u/SuurSieni Apr 14 '22

Creating plots with Seaborn is really fast and easy, but it of course requires the initial effort for the know-how. Not as fast as a couple clicks, but in the ball-park of doing the clicks for several plots. What makes the plotting easy, is the capability to just give data column names as arguments for aesthetic customization and multi-panel plotting.

As an example, consider a data frame df with observations as rows and with columns "person", "location", "height" and "weight". Using df, a scatter plot with variable-dependent marker styles and colors can be created with one command:

seaborn.relplot(df, x="height", y="weight", hue="location", style="person")

To create a plot with multiple panels from subsets of the data, one could for instance add row="location" to the above command to get a panel for each unique location in the data set. There's of course a lot more, but this should suffice.

3

u/SirGeremiah Apr 14 '22

That's very cool. So, really, as with many things it'd be better for some situations where there are variations (like the location) and where we can expect to need to create very similar graphs off very similar data, but not better for one-offs.

2

u/SuurSieni Apr 14 '22

Yes, if the data is processed in Excel then it would be fair to say so. However, as Python is more versatile than Excel, I find that generally it's just simpler to perform entire workflows in Python, R or what-have-you. But YMMV. I do still occasionally use Excel for quick post-processing, if just to provide the results in the receiver's preferred format.

2

u/SirGeremiah Apr 14 '22

I'm generally getting data that's already in Excel (where data is relatively small, that's the de facto standard for delivery in a lot of places).

1

u/InterestingNoise9598 Apr 13 '22

Thanks! This is a pretty slick resource <3

5

u/synthphreak Apr 13 '22

nice

I personally think Excel's default graphs look like crap. I think we're just used to them.

You can create a lovely histogram with just a single line using matplotlib: plt.hist(data).

15

u/omgu8mynewt Apr 13 '22

I'm a working scientist and making graphs in python is genuinely terrifying and not-intuitive at all, whereas Excel is very visual and easy to make a simple graph, and change the settings to improve the appearance. I've tried matplotlib a few times and use R, but the learning curve is SO steep for people not from computing backgrounds.

3

u/bonferoni Apr 13 '22

Try plotly.express. Literally a one liner, just a chart type, x, y with bonus options available if you wanna get fancy

2

u/Eurynom0s Apr 14 '22

You're just afraid of matplotlib, which is perfectly reasonable, it IS a terrifying mess. plotly.express is a good suggestion.

2

u/warbird2k Apr 14 '22

There are some cool jupyter lab extentions out there, like Mito and Lux. Mito let's you work with dataframes like they were å spreadsheet and spits out pandas code. I use it to get better at pandas. Lux recommends charts based on your dataframe and intent, and gives you the matplotlib code for it.

0

u/synthphreak Apr 13 '22

I definitely get that. But it also swings both ways.

I used to use Excel all the time - I would almost call myself a power user. But since learning to code, I basically never use Excel, and I've forgotten a lot of how to use it. So if someone asked me to create a chart in Excel, I would really struggle to create and customize it.

In other words, Excel is intuitive only if you're already used to using it. The same is true for matplotlib.

I don't think there's anything that makes Excel plotting objectively easier, other than the fact that the UI is graphical.

5

u/kilroy_wh Apr 13 '22 edited Apr 13 '22

Agree to disagree. It is way easier to have nice graphs in python than in excel. Especially if you need to make a change (color, scale, markers, whatever). In python, explicitly in matplotlib its just a letter or a command and in excel too many hidden clicks

Edit: spelling

4

u/Hateitwhenbdbdsj Apr 13 '22

You still need to know how to set up an environment, how to get your data in in the right format, how to use whatever library you're using for plot generation, and how to customize that plot. I agree once you know how to make graphs and modify them, it's easier to do in Python, but if you're a complete newbie to excel and python and you want to make a graph, then I think excel is much easier

3

u/dutchmaster77 Apr 13 '22

Yeah and they are always changing it in Excel. I don’t use it to make charts very often, maybe once a year or every other year even, and the process is different and unintuitive every time. Always feels like there’s advanced functionality that should be right there but I can never find

1

u/Hextall2727 Apr 13 '22

It's sometimes easier to make them in excel... but way harder to update with new data relative to using Python.