简体   繁体   English

熊猫csv导入第一行

[英]Pandas csv import first row

I need help importing a csv into the python using pandas 0.7.3 I can get the data into python but the columns are read in as one column. 我需要使用pandas 0.7.3将csv导入python的帮助,我可以将数据导入python,但将列读为一列。 See example below. 请参见下面的示例。

In [12]: data=pd.read_csv(file)'
In [13]: data[:3]
Out[13]:
        Area    Circ.   AR      Round   Solidity
0  1    31650   0.368   2.973   0.336   0.683
1   2   6875    0.836   1.181   0.847   0.924
2  3    12850   0.767   1.543   0.648   0.902

In [14]: data.columns
Out[14]: Index([        Area    Circ.   AR      Round   Solidity], dtype=object)

How can I import the data so I get the following data structure 如何导入数据,以便获得以下数据结构

In [14]: data.columns
Out[14]: Index([Area, Circ., AR, Round, Solidity,], dtype=object)

such that 这样

In [15]:data['area']
Out[15]:
31650
6875
12850
etc

Thanks. 谢谢。

CSV = Comma Separated Values - so normally pandas is searching ; CSV =逗号分隔值-因此通常熊猫正在搜索; as separator. 作为分隔符。

You can use sep= in read_csv to define separator. 您可以在read_csv使用sep=来定义分隔符。
You can use even regular expression in definition. 您甚至可以在定义中使用正则表达式。
For example I define separator as one or more spaces. 例如,我将分隔符定义为一个或多个空格。

df = pd.read_csv(file, sep='\s+')

BTW: the newest version is 0.14 - upgrade pandas . 顺便说一句:最新版本是0.14-upgrade pandas

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

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