首页 > 解决方案 > 如何在 python 中使用 .format 打印出数据形状

问题描述

我正在尝试在 python 中使用 .format 打印数据框的形状

尝试使用合并.format.shape命令的打印语句

df_shape = df.shape
print("The data has Rows {}, Columns {}".format(df_shape[0])) 

我得到的错误

IndexError: tuple index out of range

标签: pythonstring.format

解决方案


做这个 :

df_shape = df.shape print("The data has Rows {}, Columns {}".format(df_shape[0], df_shape[1]))

或这个:

df_shape = df.shape print("The data has Rows {}, Columns {}".format(*df_shape))

推荐阅读