Ben Chuanlong Du's Blog

It is never too late to learn.

`ifelse` on Pandas Series

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Series.apply + Lambda Function

DataFrame.apply + Lambda Function

axis=1: apply the lambda function on each row

List Comprehension

numpy.where

numpy.where is vectorized ifelse.

Get Location of Max Value in a Pandas Series

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

idxmax Return the row label of the maximum value.

argmax: Return int position of the largest value in the Series.

Python Modules for Visualization

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

The website The Python Graph Gallery displays hundreds of charts, always providing the reproducible python code! It aims to showcase the awesome dataviz possibilities of python and to help you benefit …

Cast Types of Columns in Pandas

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Tips and Traps

  1. You can use the method Series.astype to cast the type of a series.

  2. Series.astype(str) converts NaNs to the string literal nan. This is often NOT what people want. A better way is to use Series.astype(object)