これは簡単な質問ですが、オンラインで回答を見つけるのは驚くほど困難です。状況は次のとおりです。
>>> A
[('hey', 'you', 4), ('hey', 'not you', 5), ('not hey', 'you', 2), ('not hey', 'not you', 6)]
>>> A_p = pandas.DataFrame(A)
>>> A_p
0 1 2
0 hey you 4
1 hey not you 5
2 not hey you 2
3 not hey not you 6
>>> B_p = A_p.pivot(0,1,2)
>>> B_p
1 not you you
0
hey 5 4
not hey 6 2
これは、ドキュメントで提案されているものとはまったく異なりpivot
ます。左上隅に 1 と 0 がない結果が表示されます。そして、それが私が探しているものであり、次のように印刷される DataFrame オブジェクトです
not you you
hey 5 4
not hey 6 2
問題は、通常の動作では、最初の行が次の csv ファイルになることです。
0,not you,you
本当に欲しい時
not you, you
通常の csv ファイル (前に「0」が付いている) を R に読み込むと、フレーム オブジェクトから列名と行名が適切に設定されないため、正しい形式にするための手動操作が面倒になります。ピボットを取得して、左上隅に追加情報を表示せずに DataFrame オブジェクトを提供する方法はありますか?