我正在尝试按如下方式打印输出。
字符串:[“猫”、“狗”、“大”]
Print:
0 1 2
0 c a t
1 d o g
2 b i g
但我似乎无法正确打印索引
for i in a:
for j in i:
print(j, end=' ')
print()
我知道这会打印矩阵本身,但不会提供我需要的行号和列号
最佳答案
Pandas 的理想工作:
import pandas as pd
lst = ["cat", "dog", "big"]
df = pd.DataFrame([[y for y in x] for x in lst])
print(df)
# 0 1 2
# 0 c a t
# 1 d o g
# 2 b i g
关于Python在二维矩阵上打印行数和列数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59062284/