python-3.x - 如何使用 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'
解决方案
pandas.core.series.Series
没有reshape
。
也许:
mpg_matrix = mpg.values.reshape(-1,1)
即得到底层numpy
数组并重塑它。
推荐阅读
- angular - 除非我清理浏览器,否则 https 重定向中的 CORS 策略已阻止访问 XMLHttpRequest
- java - 如何使用 dto 类一对多地编写两个对象?
- javascript - 反应多个项目删除?
- angular - 我们如何在初始页面加载时动态设置表单数组控件的错误
- java - 二维数组的 ArrayList
- gimp - 如何在 Python-Fu 中使用 file_ico_save 设置不同图标层的属性?
- c++ - CGAL 输出参数化网格
- ios - ReplayKit 权限中显示的应用名称
- laravel - Laravel Nova Date 字段总是提交 null
- php - 在 PHP 中,如何访问没有链接的外部 CSV 文件,即没有