Kang lib of Python package: calculate my math function
Project description
welcome to Kang digital magic world: V0.3:calculate_weighted_value thank you for your trust. if you have any questions, please contact me. kangxiaowen@gmail.com
首先,创建两个DataFrame:一个是活动水平序列,另一个是权重序列。请看以下的Python代码:
import pandas as pd
import kanglib
import matplotlib.pyplot as plt
# 创建一个日期范围
dates = pd.date_range(start='2022-01-01', periods=365)
# 创建活动水平DataFrame
activity_levels_df = pd.DataFrame({
'date': dates,
'activity_level': [0.2] * len(dates)
})
# 创建权重DataFrame
weights_df = pd.DataFrame({
'date': dates,
'weight': [0.5] * len(dates)
})
# 合并这两个DataFrame
df = pd.merge(activity_levels_df, weights_df, on='date')
# 使用calculate_weighted_value函数
df = kanglib.calculate_weighted_value(df, ['activity_level'], 'weight', 'result')
# 打印DataFrame
print(df)
# 绘制结果
plt.plot(df['date'], df['result'])
plt.title('Weighted Activity Level over Time')
plt.xlabel('Date')
plt.ylabel('Weighted Activity Level')
plt.show()
这段代码首先创建了两个DataFrame,一个包含活动水平,另一个包含权重,都是针对相同的日期范围。然后,它们被合并到同一个DataFrame中,然后使用calculate_weighted_value
函数计算加权活动水平。然后它打印出这个DataFrame,并将结果列绘制成一条折线图,x轴是日期,y轴是加权活动水平。
python setup.py sdist bdist_wheel
twine upload dist/*
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
kanglib-0.4.tar.gz
(2.4 kB
view details)
Built Distribution
kanglib-0.4-py3-none-any.whl
(2.6 kB
view details)
File details
Details for the file kanglib-0.4.tar.gz
.
File metadata
- Download URL: kanglib-0.4.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 982d4deedb0e125f35604cb834a6233bdda0fff9d43ff21a7388bc7536268ab5 |
|
MD5 | 9fdddaa8b63181c3e48a74ff1da5866b |
|
BLAKE2b-256 | 81a5f3475743fa4875c7e6bfec06908fd4dca1bc3ba17746e5803d6c4529231f |
Provenance
File details
Details for the file kanglib-0.4-py3-none-any.whl
.
File metadata
- Download URL: kanglib-0.4-py3-none-any.whl
- Upload date:
- Size: 2.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b631b5ed285e8e0609a6a65fc730ab3d6c509851480eba9c671123f1a495615d |
|
MD5 | c130ed15c4a44122a9523b21eddba7ba |
|
BLAKE2b-256 | 94565826c8896e14717891f83a453eadc9732da0c09857b38ca7c0977980f7c6 |