Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Pipe separated data to Dataframe in Python Pandas

I have pipe-separated values like this:

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|

I have to create a Pandas DataFrame out of this data, with each column given a name.

like image 986
itsaruns Avatar asked Jan 06 '14 12:01

itsaruns


1 Answers

Here you go:

>>> 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
like image 118
elyase Avatar answered Sep 23 '22 18:09

elyase