【问题标题】:How to convert Columnar data into rows如何将列数据转换为行
【发布时间】:2019-08-05 15:36:32
【问题描述】:

我在每个国家/地区的列中都有数据,我正在尝试将其转换为名称为国家/地区的行,其中所有国家/地区名称及其值在另一个字段中。

尝试了 pivot、pivot_table 但没有按预期工作。

【问题讨论】:

  • 添加具有所需输出的样本数据
  • 阅读minimal reproducible exampleedit你的问题。
  • 在没有任何信息的情况下,您希望我们如何提供帮助? ;)

标签: python pandas pivot


【解决方案1】:
df = pd.DataFrame(
   columns=["Country 1", "Country 2", "Country 3"],
   data=[[1,2,3]]
)

所以这是你当前的输出?

   Country 1  Country 2  Country 3
0          1          2          3

你想转置它吗?

df.transpose()

           0
Country 1  1
Country 2  2
Country 3  3

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多