[英]How can i convert this lists object into a dataframe?
I have something which lokos like (called lines)我有一些 lokos 喜欢的东西(称为线条)
[' id\t Name\t Type\t User\t Q\t country\t Final-score\t Progress\t website',
'abcde\t jen\t engineer\t jenabc\t RUNNING\t UK\t 75%\t N/A',
'fres\t Penny\t dr\t dr123\t RUNNING\t DENMARK\t 67%\t N/A']
each line which is in the speech marks and separated by ',' is a dataframe row.语音标记中以“,”分隔的每一行是 dataframe 行。 However i cannot convert to dataframe.但是我无法转换为 dataframe。
new_df = pd.read_csv(StringIO(",".join(lines[1:])),sep = "\t")
i do [1:] since the first line is just a comment.我做 [1:] 因为第一行只是一个评论。 i get the error: ParserError: Error tokenizing data. C error: Expected 963 fields in line 3, saw 1099
我收到错误: ParserError: Error tokenizing data. C error: Expected 963 fields in line 3, saw 1099
ParserError: Error tokenizing data. C error: Expected 963 fields in line 3, saw 1099
i'd like my datframe to be such that the first row is the headers, and the rest are the contents separated by \t.我希望我的 datframe 的第一行是标题,而 rest 是由 \t 分隔的内容。 how can i do this?我怎样才能做到这一点?
df = pd.read_csv(StringIO("\n".join(lines)), sep=r"\s+")
print(df)
Prints:印刷:
id Name Type User Q country Final-score Progress website
0 abcde jen engineer jenabc RUNNING UK 75% NaN NaN
1 fres Penny dr dr123 RUNNING DENMARK 67% NaN NaN
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.