问题描述
我们有一个外部清单,其中有五个内部清单用于商品价格。在此外部列表中:
- 内部列表表示一天中的价格
- 内部列表中的每个值代表当日给定时间的商品价格
我需要对价格进行归一化,因此第一个值等于100,其他价格也进行了相应调整。
如果列表长度不同,我还想引发valueError
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 (将#修改为@)