DEV
[TIL] python에서 dataframe를 깔끔하게 Print 출력시키기 220920-3
에스프리터
2022. 9. 20. 12:26
728x90
💡 Today I Learned 요약 (8회차)
- tabulate를 이용해 Dataframe을 깔끔하게 print 할 수 있다
python에서 dataframe를 깔끔하게 Print 출력시키기
python에서 dataframe을 print 출력하면 줄 간격 등이 맞지 않아 알아보기 힘들게 출력이 된다. 그때 도움이 되는 것이 tabulate다.
from tabulate import tabulate
설치후 아래와 같이 그냥 print가 아닌 tabulate를 걸어주고 출력하면 예쁘게 출력되는 것을 볼 수 있다. 템플릿도 사용할 수 있으니 참고.
>>> from tabulate import tabulate
>>> table = [["Sun",696000,1989100000],["Earth",6371,5973.6],
... ["Moon",1737,73.5],["Mars",3390,641.85]]
>>> print(tabulate(table))
----- ------ -------------
Sun 696000 1.9891e+09
Earth 6371 5973.6
Moon 1737 73.5
Mars 3390 641.85
----- ------ -------------
#tabulate 관련 작성 및 리서치 내역:
728x90