Pandas 中的条件转置
我想在这样的条件下转置列。
df = pd.DataFrame({"Product" : ["A", "A", "A", "B", "B", "B", "C", "C", "C"],
"Question" : ["What", "When", "Where", "What", "When", "Where", "What", "When", "Where"],
"Answer" : ["Car", "Friday", "German", "Bike", "Wednesday", "France", "Train", "Sunday", "America"]})
有人能为这种情况提出有效的解决方案吗?
I wanna transpose columns in conditions like this.
df = pd.DataFrame({"Product" : ["A", "A", "A", "B", "B", "B", "C", "C", "C"],
"Question" : ["What", "When", "Where", "What", "When", "Where", "What", "When", "Where"],
"Answer" : ["Car", "Friday", "German", "Bike", "Wednesday", "France", "Train", "Sunday", "America"]})
Can anyone suggest an effective solution for this case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
pivot
:检查如何旋转数据框
Use
pivot
:Check How can I pivot a dataframe