pandas 如何在熊猫中用分隔符读取文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44747834/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to read in file with delimiter in pandas?
提问by JimLohse
I am using the pandas library and how can I split the given dataframe into rows and columns based on comma seprated. Because if I try it gives the error it cannot seprate and throws following error.
我正在使用 Pandas 库,以及如何根据逗号分隔将给定的数据帧拆分为行和列。因为如果我尝试它会给出错误,它无法分离并引发以下错误。
6.1101,17.592
5.5277,9.1302
8.5186,13.662
7.0032,11.854
5.8598,6.8233
8.3829,11.886
And the above given line consist my dataset. And the code is:
上面给定的行包括我的数据集。代码是:
import pandas as pd
from sklearn import linear_model
import matplotlib.pyplot as plt
dataframe = pd.read_fwf("challenge_dataset.txt")
回答by omri_saadon
The pandas.read_fwf
can have delimiter argument.
该pandas.read_fwf
可以有分隔符的说法。
dataframe = pd.read_fwf("challenge_dataset.txt", delimiter=",")
You can read more in pandas.read_fwf
您可以在pandas.read_fwf 中阅读更多内容
read_csvis automatically reads with comma separator, although you can change the delimiter argument in read_csv
as well.
read_csv使用逗号分隔符自动读取,尽管您也可以更改分隔符参数read_csv
。
回答by JimLohse
You need read_csv for comma separated values:
您需要 read_csv 逗号分隔值:
rt pandas as pd
dataframe = pd.read_csv("challenge_dataset.txt")
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html