Skip to content
Advertisement

null out n% values in series dictionary python

How can I randomly make n% values null in a pandas series? Let’s say I want 20% null values in my dictionary, series, or list.

input something =

JavaScript

expected output with 20% null =

JavaScript

Advertisement

Answer

You can just use series.sample(frac=%) to index and set the values in original series as None.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement