You Need to Have Flexible Thinking when Programming
Don't think about one perfect solution. Instead, start thinking about choosing an option out of the many you have to solve problems.
2 min read
If you are trying to solve a problem with programming, you may have several solutions to get the same result.
A basic idea that we don't get at the beginning because we look for that perfect solution.
It doesn’t exist.
It would be best to start thinking about choosing the "one" option, not "the" option.
Let’s say that we are facing the following problem: visualise two variables with a scatterplot.
import pandas as pd df = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/tips.csv') df.head()
In Python, you’ve got 3 libraries that can make a
Let’s observe the differences:
import matplotlib.pyplot as plt plt.scatter(x='total_bill', y='tip', data=df)
import seaborn as sns sns.scatterplot(x='total_bill', y='tip', data=df)
import plotly.express as px px.scatter(data_frame=df, x='total_bill', y='tip')
matplotliballows you to create custom plots, but you need to write more code.
seabornautomates the plot so that you don’t need to write more lines. For example,
seabornadded the x & y axis labels by default.
plotlyallows you to interact with the plot. Give it a try and hover the mouse over the points.
If you are to make a plot for an online post, you may like to use
plotly due to its interactivity. Nevertheless, you wouldn’t use it if you were writing a paper article.
I teach Python, R, Statistics & Data Science. I like to produce content that helps people to understand these topics better.
Feel free and welcomed to give me feedback as I would like to make my tutorials clearer and generate content that interests you 🤗
You can see my Tutor Profile here if you need Private Tutoring lessons.
Did you find this article valuable?
Support Jesús López by becoming a sponsor. Any amount is appreciated!