I am having a numpy array that you can get by the folowing lines of code:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import requests
from sklearn.preprocessing import MinMaxScaler
url = "https://query1.finance.yahoo.com/v7/finance/download/RELIANCE.BO?period1=1577110559&period2=1608732959&interval=1d&events=history&includeAdjustedClose=true"
r = requests.get(url)
open(stock+'.csv','wb').write(r.content) #________download the stock data and save it in a csv
r = pd.read_csv(r'RELIANCE.csv',date_parser='Date') #________read the dataset
r.head(1) #view the sample of dataset
I want to convert it to numbers between 0 and 1 with the MinMaxScaler
,So for that I wrote the following code:
rc = r['Close'] #________select only the Close column
rc = np.array(rc) #________convert it into a np.array
def remove_nan(ac): #________the dataset has an NaN value, so to remove it I made this function
array1 = np.array(ac)
nan_array = np.isnan(array1)
not_nan_array = ~ nan_array
ac = array1[not_nan_array]
return ac
rc = remove_nan(rc)
rc = rc.reshape(1, -1) #________reshaping the data for conversion, as asked in the fucntion
scale = MinMaxScaler() #________initialize the scaler
rc = scale.fit_transform(rc) #________transform the data
print('rc') #see the result
But on implementing the code, I got an np.array
that contains only 0s:
[[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…