I have a dataframe with one column and one row like:
list_id
12,13,14,16
The list_id column type is Object:
df['list'].dtypes => Object
When I try to get the number of elements in this column
l = list(df.list_id)
len(l) => 1
Or
len(df['list_id'] => 1
Why I am getting 1 instead of 4?
I want to get the count of elements as 4. What Can I do?
>Solution :
Example
data = {'list_id': {0: '12,13,14,16'}}
df = pd.DataFrame(data)
Code
df['list_id'].str.split(',').str.len()
Result
0 4
Name: list_id, dtype: int64
if you want get only 4 not series, use following code:
df['list_id'].str.split(',').str.len()[0]