Changing Pipe separated data to Dataframe in Python Pandas

后端 未结 1 1184
执念已碎
执念已碎 2021-02-19 15:16

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|
....
....
         


        
相关标签:
1条回答
  • 2021-02-19 15:30

    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
    
    0 讨论(0)
提交回复
热议问题