Answer to Question #293846 in Python for YKZ

Question #293846

"""Q5: 

Create a Pivot Table that shows the median rating for each director, grouped by their respective countries. Name your variable

'pivot_agg'

"""


AssertionError: DataFrame are different

DataFrame shape mismatch
[left]:  (19, 117)
[right]: (125, 1)





1
Expert's answer
2022-02-05T02:04:15-0500
import pandas._testing as tm


def unpivot(frame):
    N, K = frame.shape
    data = {
        "value": frame.to_numpy().ravel("F"),
        "variable": np.asarray(frame.columns).repeat(N),
        "date": np.tile(np.asarray(frame.index), K),
    }
    return pd.DataFrame(data, columns=["date", "variable", "value"])


df = unpivot(tm.makeTimeDataFrame(3))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS