繁体   English   中英

从 Postgreql 创建 pandas.DataFrame 并将多行一列转换为一行多列

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

我有一个看起来像这样的 postgresql 数据库:

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

我希望它看起来像这样: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 但我不明白怎么做?

你可以做

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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