简体   繁体   English

绕过熊猫形状 (n,1) 到形状 (n,)

[英]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.

相关问题 如何将形状 n 的数组转换为 n,m - How to covert array of shape n, to n,m 不能将数字排列成形状 (n,n) 矩阵 - cannot arrange numbers into shape (n,n) matrix 将形状数组(n,)转换为numpy形状数组(n,1) - Transform an array of shape (n,) to a numpy array of shape (n,1) 将 Numpy 数组重塑为形状为 (n, n, n) 的立方体的字典列表 - Reshaping a Numpy Array into lexicographical list of cubes of shape (n, n, n) ValueError:形状不匹配:如果类别是一个数组,它必须是形状 (n_features,) - ValueError: Shape mismatch: if categories is an array, it has to be of shape (n_features,) 如何将一系列形状为 (n,1) 的数字作为 n 个唯一数字的数组重复 4 次,形状为 (n,1) - How to repeat a series of numbers with shape (n,1) as an array of n unique numbers repeated by 4 times with a shape of (n,1) 试图了解频谱图和 n_mels 的形状 - Trying to understand shape of spectrograms and n_mels 形状不匹配:如果类别是一个数组,它必须是形状 (n_features,) - Shape mismatch: if categories is an array, it has to be of shape (n_features,) (n,) 对于 numpy 数组形状意味着什么? - What does (n,) mean for a numpy array shape? 如何在 python 中将 (5858, ) 的形状更改为 (5858, n) - How to change shape of (5858, ) to (5858, n) in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM