在Python Pandas中将管道分离的数据更改为Dataframe

时间:2014-01-06 12:23:15

标签: python pandas dataframe

我有这样的管道分隔值:

https|clients4.google.com|application/octet-stream|2296|
https|clients4.google.com|text/html; charset=utf-8|0|
....
....
https|clients4.google.com|application/octet-stream|2291|

我必须从这些数据中创建一个Pandas DataFrame,每个列都有一个名称。

1 个答案:

答案 0 :(得分:19)

你走了:

>>> import pandas as pd

>>> pd.read_csv('data.csv', sep='|', index_col=False, 
                 names=['protocol', 'server', 'type', 'value'])
Out[7]:
     protocol server                 type                        value
0    https    clients4.google.com    application/octet-stream    2296
1    https    clients4.google.com    text/html; charset=utf-8    0
2    https    clients4.google.com    application/octet-stream    2291