如何更改 Pandas Dataframe 的形状(带有“L”的行号)?

Posted

技术标签:

【中文标题】如何更改 Pandas Dataframe 的形状(带有“L”的行号)?【英文标题】:How to change the shape of a Pandas Dataframe (row number with an "L")? 【发布时间】:2017-03-19 08:51:33 【问题描述】:

我有一个形状为 (362L,) 的单列 pandas 数据框,并希望将其更改为 (362, 103)。我该怎么做?

【问题讨论】:

【参考方案1】:

刚刚想通了,既然(362L,)这个形状的对象真的是pandas系列,我只要把它改成dataframe,像这样:

pd.DataFrame(df)

就是这样!

【讨论】:

你也可以使用to_frame方法(ser.to_frame())。或者,您可以传递单个列的名称:ser.to_frame('col_name')【参考方案2】:

使用

df.iloc[:, 0].apply(pd.Series)

【讨论】:

以上是关于如何更改 Pandas Dataframe 的形状(带有“L”的行号)?的主要内容,如果未能解决你的问题,请参考以下文章