首页 > 解决方案 > 如何使用 Python 3 缩放数据

问题描述

我正在尝试使用 Python 3 扩展我的数据

但我不断收到这个错误:我不知道可能是什么问题?请问你们能帮帮我吗?我将非常感谢您的帮助!

import pandas as pd
import numpy as np
from numpy.random import randn

from pandas import Series, DataFrame
from pandas.plotting import scatter_matrix

import matplotlib as mpl
import matplotlib.pyplot as plt

from matplotlib import rcParams
from pylab import rcParams
import seaborn as sb

import scipy
from scipy import stats
from scipy.stats import pearsonr
from scipy.stats import spearmanr
from scipy.stats import chi2_contingency

import sklearn
from sklearn import preprocessing
from sklearn.preprocessing import scale

mtcars = pd.read_csv('mtcars.csv')
mtcars.columns = ['Car 
names','mpg','cyl','disp','hp','drat','wt','qsec','vs','am','gear','carb']

mpg = mtcars['mpg']

#Scale your data
mpg_matrix = mpg.reshape(-1,1)
scaled = preprocessing.MinMaxScaler()
scaled_mpg = scaled.fit_transform(mpg_matrix)
plt.plot(scaled_mpg)
plt.show()


    mpg_matrix = mpg.numpy.reshape(-1,1)                                            
tr__
  File "C:\Anaconda\lib\site-packages\pandas\core\generic.py", line 5067, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'numpy'

标签: python-3.xtransformscalescaling

解决方案


pandas.core.series.Series没有reshape

也许:

mpg_matrix = mpg.values.reshape(-1,1)

即得到底层numpy数组并重塑它。


推荐阅读