Reputation: 1117
I have a dataframe which has the below columns
Record Type Value
100 1,2,3,4,5
200 0,10
300 1
Expected results:
list1 = [1,2,3,4,5]
Upvotes: 5
Views: 13231
Reputation: 61
Maybe this way:
import pandas as pd
df = pd.DataFrame({'Record Type': ['100', '200', '300'],
'Value': [(1,2,3,4,5), (0,10), 1]})
def returnlist(df):
v = []
for i in range(df.shape[0]):
if type(df['Value'][i]) != int:
x = list(df['Value'][i])
v.append(x)
return v
Upvotes: 1
Reputation: 2045
It looks like your 'Value' values are of string data type, so this code just maps the string value to a list of ints.
list1 = list(map(int, df['Value'][0].split(",")))
Upvotes: 6