Search code examples
pythonstringpandassubsetcell

Select a subset of an object type cell in panda Dataframe


I try to select a subset of the object type column cells with str.split(pat="'")

dataset['pictures'].str.split(pat=",")

I want to get the values of the numbers 40092 and 39097 and the two dates of the pictures as two columns ID and DATE but as result I get one column consisting of NaNs.

'pictures' column:
{"col1":"40092","picture_date":"2017-11-06"}
{"col1":"39097","picture_date":"2017-10-31"}
...

Solution

  • Thanks for the replies but I solved it by loading the 'pictures' column from the dataset into a list:

    picturelist= dataset['pictures'].values.tolist()
    

    And afterwards creating a dataframe of the list made from the column pictures and concat it with the original dataset without the picture column

    two_new_columns = pd.Dataframe(picturelist)
    new_dataset = pd.concat(dataset, two_new_columns)