This is how my dataframe looks like:
account_type picture video
twitter NULL NULL
twitter https://pbs.twimg.com/media/EPlqKxKUEAARR_x.jpg NULL
twitter https://pbs.twimg.com/media/EPlqKxKUEAARR_x.jpg https://video.twimg.com/a
twitch NULL https://twitch.tv/
instagram https://scontent-lga3-1.cdninstagram.com NULL
instagram https://video-iad3-1.xx.fbcdn.net https://www.instagram.com/p
facebook https://graph.facebook.com/2 NULL
facebook NULL https://www.facebook.com/t
youtube https://i.ytimg.com/vi https://www.youtube.com/w
And this is what I want to make it look:
account_type picture video post_type
twitter NULL NULL text
twitter https://pbs.twimg.com/media/EPlqKxKUEAARR_x.jpg NULL picture
twitter https://pbs.twimg.com/media/EPlqKxKUEAARR_x.jpg https://video.twimg.com/a video
twitch NULL https://twitch.tv/ video
instagram https://scontent-lga3-1.cdninstagram.com NULL picture
instagram https://video-iad3-1.xx.fbcdn.net https://www.instagram.com/p video
facebook https://graph.facebook.com/2 NULL picture
facebook NULL https://www.facebook.com/t video
youtube https://i.ytimg.com/vi https://www.youtube.com/w video
Basically I am trying to segregate each row into a picture/video/text.
For twitter, instagram
> if columns 'picture' and 'video are NULL,'post_type'= text
> if columns 'picture' is NOT NULL and 'video' is NULL, 'post_type'= picture
> if columns 'picture' is NOT NULL and 'video' is NOT NULL, 'post_type'= video
for twitch, youtube
> if 'video' is NOT NULL ,'post_type' = video
for facebook
> if 'video' is NULL ,'post_type' = picture
> if 'video' is NOT NULL ,'post_type' = video
I am trying to create this based on null/notnull criterias. This is what I tried:
df['newtype'] = np.where(df['picture'].isnull(), '', 'picture')
df['newtype2'] = np.where(df['video'].isnull(), '', 'video')
But this creates new columns. I want everything in one column with the conditions specified. Please tell me if there is a better way to do this.