在Python Pandas中将管道分隔的数据更改为Dataframe [英] Changing Pipe separated data to Dataframe in Python Pandas
本文介绍了在Python Pandas中将管道分隔的数据更改为Dataframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的管道分隔值:
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|
我必须根据这些数据创建一个熊猫DataFrame
,并为每列指定一个名称.
I have to create a Pandas DataFrame
out of this data, with each column given a name.
推荐答案
在这里:
>>> 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
这篇关于在Python Pandas中将管道分隔的数据更改为Dataframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文