df = {'Goals': {0: '0,0,0,0', 1: '0,0', 2: '0,0,0,0,0,0', 3: '0,0', 4: '0,0'},
'Devices': {0: 'mobile,mobile,mobile,mobile',
1: 'mobile,mobile',
2: 'mobile,mobile,mobile,mobile,mobile,mobile',
3: 'mobile,mobile',
4: 'mobile,mobile'},
'Channels': {0: 'Paid Social,Paid Social,Paid Social,Paid Social',
1: 'Paid Social,Paid Social',
2: 'Paid Search,Paid Search,Paid Search,Paid Search,Paid Search,Paid Search',
3: 'Display,Display',
4: 'Referral,Referral'}}
This is what I am trying
df['New column'] = df['Devices'].str[0:df['Channels'].str.index(',')]
I am trying to get part of a string to create a new column working with pandas but the cut needs to be dynamic so I am using the function index to get the len of the string that I need, however when I run the code showed above I just get a column full of NaN. Could someone explain me what is exactly happening, I did a test using variables instead of plain numbers and it actually works but when I used pandas inside of the str function the code does not returns the result that I want.