问题描述
说我在列表中有这两个数据框,
Say I have these two Data Frames in a list,
sm = pd.DataFrame([["Forever", 'BenHarper'],["Steel My Kisses", 'Kack Johnson'],\
["Diamond On the Inside",'Xavier Rudd'],[ "Count On Me", "Bruno Mars"]],\
columns=["Song", "Artist"])
pm = pd.DataFrame([["I am yours", 'Jack Johnson'],["Chasing Cars", 'Snow Patrol'],\
["Kingdom Comes",'Cold Play'],[ "Time of your life", "GreenDay"]],\
columns=["Song", "Artist"])
df_list = [sm,pm]
现在,当我想在迭代时同时打印两个数据帧时,我得到了类似的东西,
Now, when I want to print both data frames while iterating, I get something like this,
for i in df_list:
print(i)
结果
Song Artist
0 Forever BenHarper
1 Steel My Kisses Kack Johnson
2 Diamond On the Inside Xavier Rudd
3 Count On Me Bruno Mars
Song Artist
0 I am yours Jack Johnson
1 Chasing Cars Snow Patrol
2 Kingdom Comes Cold Play
3 Time of your life GreenDay
但是,当我们执行df_list[0]
时,它以令人愉悦的表格形式打印,
However, when we do df_list[0]
it prints in a pleasing tabular manner,
当我遍历列表并打印数据框时,能否以一种视觉上令人愉悦的方式获得相同的结果?我一直在搜索,还没有运气.任何想法如何做到这一点?
Can I get that same way in a visually pleasing way when I loop through the list and print Data Frame?? I have been searching and no luck yet. Any ideas how to do that?
(对不起,如果这在python中是正常的,因为我是Python和Jupyter的新手,那么视觉上令人愉悦的浏览器会让我感到高兴)
(Sorry, if this is something that is normal in python, as I am new to Python and Jupyter, visually pleasing ones make me feel happy to see)
推荐答案
您可以使用此
from IPython.display import display
for i in df_list:
display(i)
这篇关于在Jupyter Notebook Pandas的For循环中打印视觉上令人愉悦的DataFrames的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!