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.
CodePudding user response:
You might be interested in .to_numpy()
:
array = z['0'].to_numpy()
CodePudding user response:
>>> s = pd.DataFrame({"col" : range(5)})
>>> s.shape
(5,1)
>>> s.col.to_numpy().shape
(5,)
CodePudding user response:
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.