'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 out, How to. squeeze documentation
I also tried z['0']=z['0'].squeeze() but it didn't help.
How can I convert?
Solution 1:[1]
>>> s = pd.DataFrame({"col" : range(5)})
>>> s.shape
(5,1)
>>> s.col.to_numpy().shape
(5,)
Solution 2:[2]
You might be interested in .to_numpy():
array = z['0'].to_numpy()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Amir saleem |
| Solution 2 | SultanOrazbayev |
