Pandas and Python Tips and Tricks for Data Science and Data Analysis

Take your efficiency to the next level with these Pandas and Python Tricks!

Zoumana Keita
Towards Data Science
12 min readDec 2, 2022

--

Photo by Andrew Neel on Unsplash

Motivation

This blog regroups all the Pandas and Python tricks & tips I share on a basis on my LinkedIn page. I have decided to centralize them into a single blog to help you make the most out of your learning process by easily finding what you are looking for.

The content is divided into two main sections:

  • Pandas tricks & tips are related to only Pandas.
  • Python tricks & tips related to Python.

If you are more of a video person, you can start watching my series about these tricks on my YouTube channel for more interactivity. Each video covers about two or three tricks at a time.

Pandas tricks & tips

This section provides a list of all the tricks

1. 𝗖𝗿𝗲𝗮𝘁𝗲 𝗮 𝗻𝗲𝘄 𝗰𝗼𝗹𝘂𝗺𝗻 𝗳𝗿𝗼𝗺 𝗺𝘂𝗹𝘁𝗶𝗽𝗹𝗲 𝗰𝗼𝗹𝘂𝗺𝗻𝘀 𝗶𝗻 𝘆𝗼𝘂𝗿 𝗱𝗮𝘁𝗮𝗳𝗿𝗮𝗺𝗲.

Performing simple arithmetic tasks such as creating a new column as the sum of two other columns can be straightforward.

🤔 But, what if you want to implement a more complex function and use it as the logic behind column creation? Here is where things can get a bit challenging.

Guess what…

✅ 𝙖𝙥𝙥𝙡𝙮 and 𝙡𝙖𝙢𝙗𝙙𝙖 can help you easily apply whatever logic to your columns using the following format:

𝙙𝙛[𝙣𝙚𝙬_𝙘𝙤𝙡] = 𝙙𝙛.𝙖𝙥𝙥𝙡𝙮(𝙡𝙖𝙢𝙗𝙙𝙖 𝙧𝙤𝙬: 𝙛𝙪𝙣𝙘(𝙧𝙤𝙬), 𝙖𝙭𝙞𝙨=1) 

where:

➡ 𝙙𝙛 is your dataframe.

➡ 𝙧𝙤𝙬 will correspond to each row in your data frame.

--

--