diff --git a/Extras/Omnivore/数据处理过程.md b/Extras/Omnivore/数据处理过程.md index a92cc2cb..1beb1182 100644 --- a/Extras/Omnivore/数据处理过程.md +++ b/Extras/Omnivore/数据处理过程.md @@ -253,5 +253,40 @@ plt.show() ## 支付方式统计 ```python +import pandas as pd +import matplotlib.pyplot as plt +plt.rcParams['font.sans-serif'] = ['Microsoft YaHei'] + +# Load the Excel file +data = pd.read_excel('E:/Projects/analyse/pythonProject/merged_data.xlsx') + +# Ensure '日期' is in datetime format for grouping +data['日期'] = pd.to_datetime(data['日期']) + +# Add a 'YearMonth' column for easier analysis +data['YearMonth'] = data['日期'].dt.to_period('M') + +# Group data by 'YearMonth' +grouped = data.groupby('YearMonth') + +# Assuming 'data' is your DataFrame and '支付方式' is the column for Payment Methods +data['Payment Category'] = data['支付方式'].apply(lambda x: '挂账' if '挂账' in str(x).lower() else '现付') + +# Group by 'YearMonth' and 'Payment Category', then count the occurrences +monthly_payment_category_counts = data.groupby(['YearMonth', 'Payment Category']).size().unstack(fill_value=0) + +# Calculate the percentage of 'Pending' and 'Other' categories for each month +monthly_payment_category_percentage = (monthly_payment_category_counts.div(monthly_payment_category_counts.sum(axis=1), axis=0) * 100) + +# Plotting the results - A stacked bar chart would be suitable to show percentages month-by-month +monthly_payment_category_percentage.plot(kind='bar', stacked=True, figsize=(14, 7), color=['tomato', 'lightblue']) +plt.title('支付方式占比') +plt.xlabel('月份') +plt.ylabel('比例') +plt.legend(title='支付方式') +plt.xticks(rotation=45) +plt.tight_layout() +plt.show() +``` -``` \ No newline at end of file +![image.png|600](https://image.kfdr.top/i/2024/03/16/65f56e94b7e9e.png)