How to Make your Python Modules more User Friendly

Image for post
Image for post
Photo by on

Motivation

As a data scientist, you most likely want to share the helpful modules you created with your teammates or other users. Although your module might be useful, others will not use it if it takes them a lot of effort to access the useful functions in your module.

Thus, you want to make it easy for users to use your module. The code to import and run your module should be short. In this article, I will show you 3 ways to make it easy to import and execute your Python modules.

Import Everything

Scenario

Imagine we have a file called utils.py that…


Share your Useful Python Utilities in 10 Minutes

Image for post
Image for post
Photo by on

Motivation

Did you create some useful functions or classes that you keep reusing again and again in multiple projects? Instead of copying and pasting the same code, wouldn’t it be convenient if you could just import your useful functions like below in any of your projects?

To make your package accessible to you and others, publish to . I’m sure you have come across PyPI when trying to install some Python packages. Anybody can upload their package to PyPI, including you.

Does your package need to be complicated to upload to PyPI? No! …


Debug and Create Cool Python Packages in a Few Lines of Code

Motivation

After developing a useful Python package or a useful function, you might wish for your teammates or other users to use your code. However, the output of your code in the terminal is a little bit boring and is confusing to understand.

Is there a way that you can make the output clearer and prettier like below?

Image for post
Image for post
Gif by Author

That is when Rich comes in handy. Besides beautiful printing, Rich also allows you to:

  • Produce a beautiful report on any Python object
  • Debug the output of your function
  • Create a tree to display a file structure
  • Create progress bars and status
  • Create…


Create a Deep Learning App in a Few Lines of Code

Image for post
Image for post
Image by Author

Motivation

If you want to build a deep learning app, how difficult can it be? It depends on the tools you use to build the model and application. If you want to create a deep learning model with high performance and deploy it in several lines of code, start with fastai and Streamlit.

Inspired by chapter 2 of the book, Deep Learning for Coders with fastai and PyTorch by Jeremy Howard and Sylvain Gugger, I decided to create a model to classify dogs and deploy it using Streamlit instead of Voila.

In this tutorial, I will show you how to create…


Utilize your Python skills to help your team manage their tasks

Motivation

If you are working in a team, there might be multiple projects within your team. There are also subtasks with due dates for each project. Each subtask is assigned to different team members.

The schedule is even more complicated if every member has different vacation dates. Is there a way that you can visualize all these details like below using Python?

Image for post
Image for post
Image by author

Yes, you can with python-gantt.

What is a Gantt Chart?

A Gantt chart is a bar chart that provides a visual view of tasks scheduled over time. The x-axis represents the timeline, and the y-axis presents the tasks.

There are multiple libraries in Python…


Stop writing Python functions that take more than three minutes to understand

Image for post
Image for post
Photo by on

Motivation

Have you ever looked at a function you wrote one month earlier and found it difficult to understand in 3 minutes? If that is the case, it is time to refactor your code. If it takes you more than 3 minutes to understand your code, imagine how long it would take for your teammates to understand your code.

If you want your code to be reusable, you want it to be readable. Writing clean code is especially important to data scientists who collaborate with other team members in different roles.

You want your Python function to:

  • be small
  • do one…


Are you Using Print or Log to Debug your Code? Use Icecream instead.

Image for post
Image for post
Photo by on

Motivation

If you are using print to debug your code, you might find it confusing to look at many lines of output on your terminal and then try to figure out which code each output belongs to.

For example, running the script below

will give you

30
40

Which one of these outputs is num1 ? Which one of these outputs is num2 ? Two outputs might not be so bad to figure out, but what if there are more than 5 different outputs? To try to find the source code that is responsible for the output can be time-consuming.


Have a Quick Understanding of your CSV Files through your Terminal in 1 Line of Code

Image for post
Image for post
Created by author

Motivation

Have you ever tried to have a general understanding of your CSV file by staring at it but ended up not understanding your file? You can open a Jupyter Notebook to analyze your CSV file, but it is time-consuming to open a notebook just to understand a CSV file, especially when you are working primarily with Python scripts and terminal.

Is there a way that you can quickly analyze your CSV files from your terminal in 1 line of code such as this?

$ xsv stats bestsellers.csv | xsv table

This is when xsv comes in handy.

What is xsv?

is…


Data Visualization, Natural Language Processing

Distinguish Gender in Tweets and Present them in an Interactive HTML Scatter Plot

Image for post
Image for post
Photo by on

Motivation

If you are given a tweet, can you recognize which gender it belongs to? You probably can recognize the gender of the author by looking at specific words in a tweet.

For example. if you see the word ‘cute’ in a tweet, there is a high percentage that the author is female. Because some words are used more often by a certain gender, it is possible for machine learning models to distinguish between different genders using these gender-related words.

Wouldn’t it be interesting if we can visualize how different words are related to different genders on Twitter? That could be…


Bored with Your Terminal Output? Let’s Change its Color and Shape!

Image for post
Image for post

Motivation

If you are working with Python, you probably print the output on the terminal either to debug or to be informed of the process. However, if the output is lengthy, it is difficult to keep track of the output.

Is there a way that you can make the important terminal output stand out more such as adding color, and enlarging the text like below?

Khuyen Tran

Data scientist. I share a little bit of goodness every day through articles and daily data science tips:

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store