如何更改 Pandas 数据框的形状(带有“L”的行号)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40440997/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change the shape of a Pandas Dataframe (row number with an "L")?
提问by George Liu
I have a one column pandas dataframe of the shape (362L,)
, and would like to change it to (362, 103)
. How can I do that?
我有一个形状为一列的Pandas数据框(362L,)
,并且想将其更改为(362, 103)
. 我怎样才能做到这一点?
回答by George Liu
Just figured out, since the object of the shape (362L,)
is really a pandas series, I just need to change it to dataframe, like this:
刚刚想通了,既然形状的对象(362L,)
真的是一个pandas系列,我只需要把它改成dataframe,像这样:
pd.DataFrame(df)
That's it!
就是这样!
回答by piRSquared
use
用
df.iloc[:, 0].apply(pd.Series)