2021年3月19日星期五

How to select comma separated values only in a loop?

Here is what I am trying to do. suppose this is my data column.

0                               ET Bureau  1                By Sobia Khan, ET Bureau  2                               ET Bureau  3            By Sarita C Singh, ET Bureau  4    By Dipanjan Roy Chaudhury, ET Bureau  

Here I want to run a loop and select only those values which are having comma separated values, for ex in the above data at index 1 there is a comma separated value and from that value, I need to extract only the string which is after the comma for ex from By Sobia Khan, ET Bureau I need ET Bureau only.

I tried df['column_name'].str.split(',').str[1] but it was giving me nan values for the ones which were not comma separated. So I want to run a loop only for comma separated values.

https://stackoverflow.com/questions/66718398/how-to-select-comma-separated-values-only-in-a-loop March 20, 2021 at 01:01PM

没有评论:

发表评论