Skip to content
Advertisement

Convert comma-separated values into integer list in pandas dataframe

How to convert a comma-separated value into a list of integers in a pandas dataframe?

Input:

enter image description here

Desired output:

enter image description here

Advertisement

Answer

There are 2 steps – split and convert to integers, because after split values are lists of strings, solution working well also if different lengths of lists (not added Nones):

JavaScript

Or:

JavaScript

Alternative solutions:

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