์ƒ์„ธ ์ปจํ…์ธ 

๋ณธ๋ฌธ ์ œ๋ชฉ

[TIL] python์—์„œ dataframe๋ฅผ ๊น”๋”ํ•˜๊ฒŒ Print ์ถœ๋ ฅ์‹œํ‚ค๊ธฐ 220920-3

DEVELOPMENT/Python

by ์—์Šคํ”„๋ฆฌํ„ฐ 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 ๊ด€๋ จ ์ž‘์„ฑ ๋ฐ ๋ฆฌ์„œ์น˜ ๋‚ด์—ญ:

ํƒœ๊ทธ

๊ด€๋ จ๊ธ€ ๋”๋ณด๊ธฐ

๋Œ“๊ธ€ ์˜์—ญ