I have a dataframe that looks like this:
df=pd.read_csv('https://raw.githubusercontent.com/amanaroratc/hello-world/master/ask_git.csv')
Channel_ID Video_Category_Name score_pct
0 UC--bUZc5c9WseZNqGR6KLxA Autos & Vehicles 0.213702
1 UC--bUZc5c9WseZNqGR6KLxA Entertainment 0.786298
2 UC-B1L3oT81XgeeGh6S12qgQ People & Blogs 1.000000
3 UC-N_7HFKrSsYxCSA_kfdRSA People & Blogs 0.137261
4 UC-N_7HFKrSsYxCSA_kfdRSA Pets & Animals 0.862739
... ... ... ...
819 UCzsNLZ9GrGXRjt0QmvWFm2Q Entertainment 0.945243
820 UCzsNLZ9GrGXRjt0QmvWFm2Q Film & Animation 0.002046
821 UCzsNLZ9GrGXRjt0QmvWFm2Q Music 0.002797
822 UCzsNLZ9GrGXRjt0QmvWFm2Q News & Politics 0.000433
823 UCzsNLZ9GrGXRjt0QmvWFm2Q People & Blogs 0.000358
There are 15 distinct values in Video_Category_Name
:
df.Video_Category_Name.unique()
gives
array(['Autos & Vehicles', 'Entertainment', 'People & Blogs',
'Pets & Animals', 'Howto & Style', 'Education', 'Gaming', 'Music',
'Comedy', 'Travel & Events', 'Science & Technology',
'Nonprofits & Activism', 'Sports', 'Film & Animation',
'News & Politics'], dtype=object)
In [3]: iwantthis
Out[3]:
Channel_ID Autos & Vehicles Entertainment People & Blogs ...
0 UC--bUZc5c9WseZNqGR6KLxA 0.213702 0.786298 0 ...
1 UC-B1L3oT81XgeeGh6S12qgQ 0 0 1.0000 ...
How do I create a column for each of these 15 and fill value from score_pct
(0
if it does not exist)?
Not sure how to use unstack/melt/pivot or something else