[英]Input contains infinity or a value too large for dtype('float64') error
Input contains infinity or a value too large for dtype('float64') error shows up when I run this code.当我运行此代码时,输入包含无穷大或对于 dtype('float64') 错误来说太大的值。 How can I solve it?
我该如何解决?
from sklearn import preprocessing
from tensortrade.data.cdd import CryptoDataDownload
import pandas as pd
cdd = CryptoDataDownload()
data = cdd.fetch("Bitstamp", "USD", "BTC", "1h")
for col in data.columns:
if col not in ['date', 'unix']:
data[col]=data[col].pct_change()
data.dropna(inplace=True)
data[col] = preprocessing.scale(data[col].values)
print(data.head())
You have infinite value in your data, remove them with this:您的数据具有无限价值,请使用以下命令将其删除:
data[col] =data[col][data[col] != float('inf') ]
from sklearn import preprocessing
from tensortrade.data.cdd import CryptoDataDownload
import pandas as pd
cdd = CryptoDataDownload()
data = cdd.fetch("Bitstamp", "USD", "BTC", "1h")
for col in data.columns:
if col not in ['date', 'unix']:
data[col]=data[col].pct_change()
data.dropna(inplace=True)
data[col] =data[col][data[col] != float('inf') ]
data[col] = preprocessing.scale(data[col].values)
print(data.head())
Try running this.尝试运行这个。 You need to replace Nan and Inf values with a number of your choice
您需要用您选择的数字替换 Nan 和 Inf 值
import numpy as np
from sklearn import preprocessing
from tensortrade.data.cdd import CryptoDataDownload
import pandas as pd
cdd = CryptoDataDownload()
data = cdd.fetch("Bitstamp", "USD", "BTC", "1h")
for col in data.columns:
if col not in ['date', 'unix']:
data[col]=data[col].pct_change()
data.dropna(inplace=True)
print(data[col].tolist())
# replace inf or nan with a number (for my example zero is selected)
data[col] = [0 if np.isnan(x) or np.isinf(x) else x for x in data[col]]
data[col] = preprocessing.scale(data[col].values)
print(data.head())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.