[英]Error: Input contains NaN, infinity or a value too large for dtype('float32')
I am solving a random forest regression problem.我正在解决一个随机森林回归问题。 code is below代码如下
import pandas as pd
dataset =pd.read_csv ('C:/random forest/data.csv', decimal=',')
xrf1 = dataset.iloc[:,0:3].values
RESULTS_FOLDER='C:/random forest'
model_path = os.path.join(RESULTS_FOLDER, 'modele rf1.pkl')
model = joblib.load(model_path)
predrf1 = model.predict(xrf1)
I am getting an error我收到一个错误
ValueError: Input contains NaN, infinity or a value too large for dtype('float32'). ValueError:输入包含 NaN、无穷大或对于 dtype('float32') 来说太大的值。
Here you find the link of my data在这里你可以找到我的数据的链接
https://www.dropbox.com/s/nuajvw0xuux7bm3/data.csv?dl=0 https://www.dropbox.com/s/nuajvw0xuux7bm3/data.csv?dl=0
Please help me solve this error please.请帮我解决这个错误。
The problem is that your number contains a comma, that Python does not understand.问题是您的号码包含逗号,Python 不明白。 You can verify this by typing float('-12,95525169')
, and you'll get the same error.你可以通过输入float('-12,95525169')
来验证这一点,你会得到同样的错误。
However, since you are using pandas, you can maybe solve this pretty easily.但是,由于您使用的是 pandas,因此您可以很容易地解决这个问题。
If all your floats have the same comma separator, you can use the following to read your CSV file:如果所有浮点数都具有相同的逗号分隔符,则可以使用以下内容读取 CSV 文件:
dataset = pd.read_csv("C:/random forest/data.csv", delimiter=";", decimal=",")
Adding the decimal=","
parameter, pandas will parse the string and convert it to float properly.添加decimal=","
参数,pandas 将解析字符串并将其正确转换为浮点数。
Your string has a comma in it.您的字符串中有一个逗号。 Python's formatting (and thus it's parser) uses the period as decimal separator and does not have thousands separators. Python 的格式(因此它是解析器)使用句点作为小数分隔符,并且没有千位分隔符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.