简体   繁体   中英

How to change the shape of a Pandas Dataframe

I have a one column pandas dataframe of the shape (44,1), and would like to change it to (44,). How can I do that?

I want to convert a pandas.DataFrame to a pandas.Series

Here's a quick example:

#Create dataframe
df = pd.DataFrame({'val':[1,2,3,4,5]})

#Shape of a single-column dataframe
df.shape
#Output: (5, 1)

#Shape of series
df['val'].shape
#Output: (5,)

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