在Jupyter笔记本Pandas的For循环中打印视觉上令人愉悦的数据帧

2024-04-19 20:17:13 发布

您现在位置:Python中文网/ 问答频道 /正文

假设我在一个列表中有这两个数据帧

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]

当我想打印数据时

^{pr2}$

结果

                  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]时,它以令人愉快的表格方式打印

enter image description here

当我在列表中循环并打印数据帧时,我能以一种视觉上令人愉悦的方式得到同样的结果吗??我一直在寻找,但还没有运气。有什么办法吗?在

(抱歉,如果这在python中是正常的,因为我是python和Jupyter的新手,那么视觉上令人愉悦的东西让我很高兴看到)


Tags: 数据dataframe列表songartistonmypd