阅读 pandas 中的纯文本文档,只有一栏

Read Plain Text Document in pandas, only one column

here is the photo

我该如何解决这个问题,谢谢

您必须指定 csv 文件分隔符为 whitespace。 为此,您必须添加 sep='\s+',因为这表示文件中的分隔符是一个或多个空格(正则表达式)。

更好的方法

您必须将 delim_whitespace=True 指定为参数,因为它比 regex 我上面显示的更快。

所以你的代码应该是这样的:

pd.read_csv("beer_drug_1687_1739.txt", header=None, delim_whitespace=True)

而且我还看到您的第一行有列的名称。因此,您必须将 header=None 更改为 header=[0] 以获取列的名称。

如果您有任何问题,请随时提出。