Python 规范化数据帧,然后在对从数据帧提取的值执行操作时生成NameError
我们有一个商品价格的外部清单和五个内部清单。在此外部列表中:Python 规范化数据帧,然后在对从数据帧提取的值执行操作时生成NameError,python,pandas,dataframe,normalization,nameerror,Python,Pandas,Dataframe,Normalization,Nameerror,我们有一个商品价格的外部清单和五个内部清单。在此外部列表中: 内部列表表示一天内的价格 内部列表中的每一个值都表示当天某一时刻商品的价格 我需要正常化价格,使第一个值值为100,其他价格相应调整 如果列表长度不同,我还想提出一个valueError 我的代码生成NameError,未定义标量变量 PRICES_PER_HOUR_PER_DAY_SAMPLE = [ [11300, 12000, 12100, 12100, 11800, 11100, 10300, 9400,], #
- 内部列表表示一天内的价格
- 内部列表中的每一个值都表示当天某一时刻商品的价格
PRICES_PER_HOUR_PER_DAY_SAMPLE = [
[11300, 12000, 12100, 12100, 11800, 11100, 10300, 9400,], # Prices for business hours on Monday
[10100, 10300, 10200, 10300, 10200, 10100, 10200, 10200,], # Prices for business hours on Tuesday
[10600, 10700, 10100, 10000, 9800, 8400, 7500, 9000,], # Prices for business hours on Wednesday
[9100, 9600, 10200, 10200, 10200, 10300, 10100, 10400,], # Prices for business hours on Thursday
[10500, 10600, 13200, 10800, 10500, 10200, 9900, 9800,], # Prices for business hours on Friday
"""
E.g., normalize_prices([[1, 2], [3, 4]]) is [[100, 200], [300, 400]]
E.g., normalize_prices([[200, 20], [30, 400]]) is [[100, 10], [15, 200]]
:param prices: list of list of prices
:return: normalised list of list of prices where the first price is 100
and the other prices are scaled accordingly
:rtype: list
"""
import pandas as pd
PRICES_PER_HOUR_PER_DAY_SAMPLE = [
[11300, 12000, 12100, 12100, 11800, 11100, 10300, 9400,], # Prices for business hours on Monday
[10100, 10300, 10200, 10300, 10200, 10100, 10200, 10200,], # Prices for business hours on Tuesday
[10600, 10700, 10100, 10000, 9800, 8400, 7500, 9000,], # Prices for business hours on Wednesday
[9100, 9600, 10200, 10200, 10200, 10300, 10100, 10400,], # Prices for business hours on Thursday
[10500, 10600, 13200, 10800, 10500, 10200, 9900, 9800,], # Prices for business hours on Friday
]
# Create the pandas DataFrame
df = pd.DataFrame(PRICES_PER_HOUR_PER_DAY_SAMPLE)
# print dataframe.
print(df)
# Select first value
a = df.iloc[0, 0]
# Find value used to normalize data
Scalar = a/100
print(a)
print(Scaler)
# Multiply all values in data by Scalar
PRICES_PER_HOUR_PER_DAY_SAMPLE * Scalar
'''
Traceback (most recent call last):
File "<stdin>", line 24, in <module>
print(Scaler)
NameError: name 'Scaler' is not defined
每小时每天价格样本=[
[11300、12000、12100、12100、11800、11100、10300、9400,],#周一营业时间的价格
[10100、10300、10200、10300、10200、10100、10200、10200,],#周二营业时间的价格
[10600、10700、10100、10000、9800、8400、7500、9000,],#周三营业时间的价格
[9100、9600、10200、10200、10200、10300、10100、10400,],#周四营业时间的价格
[10500、10600、13200、10800、10500、10200、9900、9800,],#周五营业时间的价格
"""
例如,正常化价格([[1,2],[3,4]])是[[100200],[300400]]
例如,正常化价格([[200,20],[30400]])是[[100,10],[15200]]
:参数价格:价格列表
:return:第一个价格为100的标准化价目表
其他价格也相应调整
:rtype:list
"""
作为pd进口熊猫
价格每小时每天样本=[
[11300、12000、12100、12100、11800、11100、10300、9400,],#周一营业时间的价格
[10100、10300、10200、10300、10200、10100、10200、10200,],#周二营业时间的价格
[10600、10700、10100、10000、9800、8400、7500、9000,],#周三营业时间的价格
[9100、9600、10200、10200、10200、10300、10100、10400,],#周四营业时间的价格
[10500、10600、13200、10800、10500、10200、9900、9800,],#周五营业时间的价格
]
#创建数据帧
df=pd.数据帧(每小时每天的价格样本)
#打印数据帧。
打印(df)
#选择第一个值
a=df.iloc[0,0]
#查找用于规范化数据的值
标量=a/100
印刷品(a)
打印(定标器)
#将数据中的所有值乘以标量
价格每小时每天样本*标量
'''
回溯(最近一次呼叫最后一次):
文件“”,第24行,在
打印(定标器)
NameError:未定义名称“Scaler”
嗯……您创建了一个名为Scalar
的变量,但调用了Scaler
…请注意,前者有两个a