Skip to main content

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/*


使用示例

下面是如何使用 kanglib.calculate_weighted_value 函数的示例:

import pandas as pd
import kanglib
import matplotlib.pyplot as plt
import numpy as np

# 创建一个日期范围
dates = pd.date_range(start='2022-01-01', periods=365*2)

# 创建活动水平DataFrame
activity_levels_df = pd.DataFrame({
    'date': dates,
    'activity_level': np.random.rand(len(dates))
})

# 创建权重DataFrame
weights_df = pd.DataFrame({
    'date': dates,
    'weight': np.random.rand(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()

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.5.tar.gz (2.7 kB view hashes)

Uploaded Source

Built Distribution

kanglib-0.5-py3-none-any.whl (3.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page