import numpy as np
names
names = np.array(['Apple Inc', 'Coca-Cola', 'Walmart'])
negative_index = np.array([-1,-2])
Use slicing on list names
names_subset = names[negative_index]
print(names_subset)
注意哪里中括号哪里小括号,哪里逗号哪里冒号
这个做法 可以先显示最后一个 再显示倒数第二个
结果: ['Walmart' 'Coca-Cola']
For lists, useful functions include max() and min(), which identify the maximum or minimum value in a list. A useful list method is .sort() which sorts the elements in a list.
prices = [159.54, 37.13, 71.17]
price_max = max(prices) max是一个函数
但是method功能的话 是prices_min = prices.sort() 放在点变量的后面
names = ['Apple Inc', 'Coca-Cola', 'Walmart']
names.append('Amazon.com')
print(names)
['Apple Inc', 'Coca-Cola', 'Walmart', 'Amazon.com'] 是加一个元素,元素的总数量增加了
.extend() 可以在后面添加多个元素
.index 返还的是 index数字
np.pmt() 企业年金
rf = pd.DataFrame.from_dict(tt, orient="index");
rf.to_csv("LocalDrive\\Sales.csv")
计算加权平均数~~
# Create the combined list for sales and probability
sales_probability = ['0|0.05', '200|0.1', '300|0.4', '500|0.2', '800|0.25']
weighted_probability = 0
# Create a for loop to calculate the weighted probability
for pair in sales_probability:
parts = pair.split('|')
weighted_probability += float(parts[0]) * float(parts[1])
# Print the weighted probability result
print("The weighted probability is {}.".format(weighted_probability))