Below is a sample string . How can i convert this string to a pandas Dataframe?
str1 =
"""
Feature Id & Feature Desc Status Failed Total
--------------------------------------------------- -------- ------ -----
RKSPACE (RackSpace Test In) Passed 0 1
D1 (Drum 1 Test) Passed 0 1
D2 (Drum 2 Test) Passed 0 1
D3 (Drum 3 Test) Passed 0 1
PRIMUS (PRIMUS Ink Test) Not-run 0 0
RGB (RGB Color Test) Passed 0 1
YONO (App Test) Not-run 0 0
PSENSE (Paper Sensor Test) Not-run 0 0
TFlag (Flag Test) Not-run 0 0
MEMT (Memory Test) Passed 0 1
CRG (CARRIAGE Test) Not-run 0 0
"""
I have tried the below code
import pandas as pd
from StringIO import StringIO
def get_dataframe(str1):
test_data = StringIO(str1)
df = pd.read_csv(test_data, sep=r'\s+', comment='--', engine='python')
return df
The result I am getting is ugly and not correct. Result Image I have checked other posts, but didn't find any question that deals with spaces in the string. Normally, if there were no spaces in the 1st column, this would have been easy to get the Dataframe, but how do I convert it to dataframe preserving the same format as the str1? Any help would be appreciated . Thanks