23

A Comprehensive Guide to List Comprehensions

 4 years ago
source link: https://www.tuicool.com/articles/EBfU7fB
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

A Comprehensive Guide to List Comprehensions

Let’s be honest — your feature engineering skills probably aren’t at a level you want them to be, and you don’t know what to do about it. For a long period ( longer than I’d like to admit ) I’ve been using all kind of Pandas operations spread out on multiple rows, just to perform simple operations — like extracting a part of one column into another — when in reality most of the stuff can be done in one line of code.

VZ7fmy7.jpg!web

Photo by Marius Niveri on Unsplash

List comprehensionsare a way of doing so. If I was trying to sell you something, now would be the time to tell you how they are simple and intuitive, and they are ( after spending a couple of days dangling with them ), but for a beginner, they might seem intimidating.

This article will try to explain list comprehensions in as simple language as possible and show their use cases in data science. Now there’s no much point of me yapping around, so let’s dive straight in.


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK