If the data is a string, StringIO
from the standard io
library could be used to convert to file-like object, which could be read as csv. Also, since the data don't seem to have a header, header=None
could be passed, so that pandas won't read the first row of data as the header. Also an off-the-shelf method to add a prefix to column names (add_prefix()
) could be used to make column labels more "label-like".
data = """
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|
"""
from io import StringIO
sio = StringIO(data)
df = pd.read_csv(sio, sep='|', header=None).add_prefix('col_').dropna(how='all', axis=1)
