如何解决对数据帧进行规范化,然后对从数据帧中提取的值执行操作时生成NameError
我们有一个外部清单,其中有五个内部清单用于商品价格。在此外部列表中:
- 内部列表表示一天中的价格
- 内部列表中的每个值代表当日给定时间的商品价格
我需要对价格进行归一化,因此第一个值等于100,其他价格也进行了相应调整。
如果列表长度不同,我还想引发valueError
我的代码生成一个NameError,未定义标量变量
PRICES_PER_HOUR_PER_DAY_SAMPLE = [
[11300,12000,12100,11800,11100,10300,9400,],# Prices for business hours on Monday
[10100,10200,10100,# Prices for business hours on Tuesday
[10600,10700,10000,9800,8400,7500,9000,# Prices for business hours on Wednesday
[9100,9600,10400,# Prices for business hours on Thursday
[10500,10600,13200,10800,10500,9900,# 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,# 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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。