简体   繁体   中英

bypandas shape (n,1) to shape (n,)

I have a pandas dataframe and I want to convert it from (n,1) to shape (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.

You might be interested in .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. of course maybe its because I just had one columns, and didn't check it for more columns.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM