[英]bypandas shape (n,1) to shape (n,)
I have a pandas dataframe and I want to convert it from (n,1) to shape (n,).我有一个 pandas dataframe,我想将它从 (n,1) 转换为形状 (n,)。 probably I have to use squeeze but can't figure it out.
可能我必须使用挤压但无法弄清楚。 squeeze documentation
压缩文档
by the way z['0']=z['0'].squeeze()
didnt help.顺便说一句
z['0']=z['0'].squeeze()
没有帮助。
You might be interested in .to_numpy()
:您可能对
.to_numpy()
感兴趣:
array = z['0'].to_numpy()
>>> s = pd.DataFrame({"col" : range(5)})
>>> s.shape
(5,1)
>>> s.col.to_numpy().shape
(5,)
z=z.squeeze()
works the best and keeps the result dataframe. z=z.squeeze()
效果最好,并保持结果 dataframe。 of course maybe its because I just had one columns, and didn't check it for more columns.当然可能是因为我只有一列,并没有检查更多列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.