I have this 2 tables below:
https://i.stack.imgur.com/e9Um6.png
Is there a library or some built-in function that fills up the second table matching row and columns from it, with the information on the first one?
Thanks!
In line with Nick ODell's suggestion, you can use DataFrame.pivot
, as long as each combination of date and category is unique (because df.pivot
does not support aggregation).
Assuming your column names are integers 0, 1, and 2, try:
# Arguments: index, columns, values
# fill NaN with 0 to match your expected output
df.pivot(0, 1, 2).fillna(0)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.