简体   繁体   English

熊猫在多列上枢轴显示“ DataFrame的真值不明确”

[英]pandas pivot on multiple columns gives “The truth value of a DataFrame is ambiguous”

print a.head()
        SubjectID    form_name feature_name feature_value feature_delta
0         533  Demographic       Gender             F           0.0
1         533  Demographic          Age            65           0.0
2         533  Demographic         Race         White           0.0

This pivot, with SubjectID as the index works: SubjectID作为索引的这一枢轴有效:

print a.pivot(index='SubjectID', columns='feature_name', values='feature_value').head()
feature_name Age Gender   Race
SubjectID                     
100256        53      M  White
100626        58      M  White
100806        66      M  White

and the same thing only with [SubjectID] as the index doesn't: 而只有索引[SubjectID]的情况却不一样:

print a.pivot(index=['SubjectID'], columns='feature_name', values='feature_value').head()
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Any ideas? 有任何想法吗?

Function pivot doesn't support multiple columns and indexes, I think it is not implemented yet. 函数枢纽不支持多个列和索引,我认为它尚未实现。
Issue No. 8160 and source1 . 发行号8160source1

But my error is different: 但是我的错误是不同的:

a.pivot(index=['SubjectID'], columns='feature_name', values='feature_value').head()

ValueError: Wrong number of items passed 3, placement implies 1 ValueError:错误的项目数传递了3,放置意味着1

But: 但:

print a.pivot(index='SubjectID', columns=['feature_name'], values='feature_value').head()

ValueError: The truth value of a DataFrame is ambiguous. ValueError:DataFrame的真值不明确。 Use a.empty, a.bool(), a.item(), a.any() or a.all(). 使用a.empty,a.bool(),a.item(),a.any()或a.all()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM