【问题标题】:Converting multiple lists into column (or tabular) format [closed]将多个列表转换为列(或表格)格式[关闭]
【发布时间】:2021-03-22 10:28:09
【问题描述】:

我有多个列表如下:-(我正在使用 Python)

l1 = [mo 275 336]
l2 = [m1 334 776]

我需要将其更改为列格式如下:-

m0  275  336
m1  334  776

我已经尝试了很多东西,但它没有出现。我该如何处理?

【问题讨论】:

  • 请在真正的Python中添加你的代码sn-ps
  • 在“很多事情”中,请分享您最惊讶的一项,因为它不起作用,人们将能够帮助改进或解释问题。
  • 你想要一个 Pandas 数据框吗? This answer 展示了如何做到这一点,尽管问题有点不同。

标签: python list


【解决方案1】:

如果您不限制使用其他软件包,请尝试-

    import numpy as np
    import pandas as pd
    mat = np.asarray([l1, l2])
    df = pd.DataFrame(mat)

>>> df
    0    1    2
0  mo  275  336
1  m1  334  776

你也可以试试-

>>> df_no_indices = df.to_string(index=False)
>>> print(df_no_indices)
  0    1    2
 mo  275  336
 m1  334  776

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-03
    • 2022-01-22
    • 1970-01-01
    • 2021-01-06
    • 2014-08-04
    • 1970-01-01
    相关资源
    最近更新 更多