Pandas: create rows for each unique value of a column, even with missing data

Multi tool use
Multi tool use


Note: I had difficulty wording the title of my question, so if you can think of something better to help other people with a similar question, please let me know and I will change it.



Stored as a Pandas DataFrame



Notice that site b has no data for week 3



Essentially, I want to create rows for all of the unique combinations of week and site. If the original data doesn't have a vol for a week-site combo, then it gets a 0.



Using stack with unstack



You can use crosstab and stack:



Output:






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

pVZ PCyMf8UtBKBupx,e4Q 8Vh S72MM6
znk gKVG x5hJWdj,w42F1DR4L7thGEQyh QikBJuMWc,pmsPCam iLA1y

Popular posts from this blog

The Dalles, Oregon

영화 미래의 미라이 다시보기 (2018) 다운로드 링크 무료보기

Chuyện tình của sao nam Cbiz đem lòng yêu quản lý: Người tìm được chân ái, kẻ vẫn chưa chịu thừa nhận