pandas 可以读取转置的CSV吗? [英] Can pandas read a transposed CSV?

查看:111
本文介绍了 pandas 可以读取转置的CSV吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pandas可以读取转置的CSV吗?这是文件(请注意,我也想选择一个列的子集):

Can pandas read a transposed CSV? Here's the file (note I'd also like to select a subset of columns):

A,x,x,x,x,1,2,3
B,x,x,x,x,4,5,6
C,x,x,x,x,7,8,9

想要获取此DataFrame:

Would like to get this DataFrame:

   A  B  C
0  1  4  7
1  2  5  8
2  3  6  9

推荐答案

pd.read_csv('file.csv', index_col=0, header=None).T

这篇关于 pandas 可以读取转置的CSV吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆