いくつかの長いフィールドを持つ表形式のデータがあります。Pandas は、次のようにいくつかの長いフィールドを切り捨てます。
shortname title \
0 shc Shakespeare His Contemporaries
1 folger-shakespeare Folger Shakespeare Library Digital Texts
2 perseus-c-greek Perseus Canonical Greek
3 stanford-1880s Adult British Fiction of the 1880s, Assembled ...
4 reuters-21578 Reuters-21578
5 ecco-tcp Eighteenth Century Collections Online / Text C...
centuries
0 16th, 17th
1 16th, 17th
2 NaN
3 NaN
4 NaN
5 18th
を使用するtabulate.tabulate()と、次のようになります。
- ------------------ -------------------------------------------------------------------------- ----------
0 shc Shakespeare His Contemporaries 16th, 17th
1 folger-shakespeare Folger Shakespeare Library Digital Texts 16th, 17th
2 perseus-c-greek Perseus Canonical Greek nan
3 stanford-1880s Adult British Fiction of the 1880s, Assembled by the Stanford Literary Lab nan
4 reuters-21578 Reuters-21578 nan
5 ecco-tcp Eighteenth Century Collections Online / Text Creation Partnership ECCO-TCP 18th
- ------------------ -------------------------------------------------------------------------- ----------
最初のケースでは、幅はおよそ 80 に設定されており、端末ウィンドウを埋めるために拡張されません。「短い名前」、「タイトル」、および「世紀」の列を同じ行に配置したいので、これは機能しません。
2 番目のケースでは、幅はデータの幅に設定されますが、タイトルが非常に長い場合は機能しません。また、ユーザーの端末ウィンドウが小さい場合は、非常に奇妙に折り返されます。
だから私が探しているのは、ユーザーの端末の幅に応じて表形式のデータをきれいに印刷する、または少なくともユーザーの端末の幅を指定できるようにする (できれば簡単な) Python の方法ですtabulate(data, 120)。列。それを行う方法はありますか?