简体   繁体   中英

create pandas.DataFrame from Postgreql and convert multiple rows and one column to one row and multiple column

i have a postgresql db that look like this:

price
1
2
4
9
7
8
3
7
5
3
7

and I want it to look like this: 1 2 4 9 7 8 3 7 5 3 7

I'm reding it using pandas.read_sql() now I want to convert that the DataFrame will be instead of 11 rows and one column to be 1 row and 11 column, from what I'm understanding I need to use the pandas.melt() function but I didn't understand how?

You can do

df.T
Out[7]: 
       0   1   2   3   4   5   6   7   8   9   10
price   1   2   4   9   7   8   3   7   5   3   7

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