[英]Pandas is making an error while reading a column from a csv file
So I have a google stock dataset that has a 'Date', 'Open', 'High', 'Low', 'Close' and 'Volume' columns.所以我有一个谷歌股票数据集,它有一个“日期”、“开盘”、“高”、“低”、“收盘”和“成交量”列。 The problem is that pandas keeps saying that the 'Close' column is of type 'Object'.
问题是 pandas 一直说“关闭”列是“对象”类型。
I found the problem when I tried to scale that column using the MinMaxScaler
and that's when I got this error: could not convert string to float: '1,008.64'
当我尝试使用
MinMaxScaler
缩放该列时,我发现了问题,这时我得到了这个错误: could not convert string to float: '1,008.64'
When I tried converting it to a float using the astype('float')
function, I get the same error.当我尝试使用
astype('float')
function 将其转换为浮点数时,我得到了同样的错误。 When I try the to_numeric(price['Close'], errors='coerce')
function, it just sets some rows as NULL.当我尝试
to_numeric(price['Close'], errors='coerce')
function 时,它只是将一些行设置为 NULL。
My code:我的代码:
import pandas as pd
train_data = pd.read_csv('drive/MyDrive/Data LSTM TimeSeries/Google_Stock_Price.csv')
price = train_data[['Close']]
price.info()
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler(feature_range=(-1,1))
price['Close'] = scaler.fit_transform(price['Close'].values.reshape(-1,1))
price['Close'] = price['Close'].astype('float')
price['Close'] = pd.to_numeric(price['Close'], errors='ignore')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.