数据分析
概述:基于某网站用户注册情况,对用户注册数据进行统计分析,从中发现产品推广对新注册用户的影响。
项目提示:
可以通过Pandas、matplotlib、seaborn等实现数据分析的展示
具体要求:
1、数据处理
读入Excel数据,对其进行预处理
2、年度注册用户分析
按月统计每一年注册用户增长情况
3、新注册用户分析
截取特点时间段,分析新注册入户情况
给你段代码,比较基础的例子。要是想再做一些展示上的细节调整,按需修改吧
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# 1. 读取并处理数据
df = pd.read_excel('users_data.xlsx', engine='openpyxl')
# 把 'add_time' 转换为 datetime 类型,并新增 'year' 和 'month' 列
df['add_time'] = pd.to_datetime(df['add_time'])
df['year'] = df['add_time'].dt.year
df['month'] = df['add_time'].dt.month
# 2. 年度注册用户分析
# 按年和月分组,统计每月的注册用户数
df_grouped = df.groupby(['year', 'month']).size().reset_index(name='counts')
# 画图展示每一年每月的注册用户增长情况
plt.figure(figsize=(15, 7))
sns.lineplot(data=df_grouped, x='month', y='counts', hue='year')
plt.title('Monthly Growth of Registered Users per Year')
plt.show()
# 3. 新注册用户分析
# 截取特定时间段,例如2017年
df_2017 = df[(df['year'] == 2017)]
# 分析2017年的新注册用户情况
df_2017_grouped = df_2017.groupby('month').size().reset_index(name='counts')
# 画图展示2017年每月的注册用户增长情况
plt.figure(figsize=(15, 7))
sns.lineplot(data=df_2017_grouped, x='month', y='counts')
plt.title('Monthly Growth of Registered Users in 2017')
plt.show()
如果有帮助,请点击一下采纳该答案~谢谢
我可以提供以下解决方案:
import pandas as pd
df = pd.read_excel('data.xlsx')
数据预处理包括数据清洗、去重、格式转换等操作,具体根据数据情况进行相应处理。
df['registration_date'] = pd.to_datetime(df['registration_date'], format='%Y-%m-%d')
然后按照年和月进行分组,统计每一年每个月的注册用户数量,可以使用groupby()函数和pivot_table()函数实现,例如:
df['year_month'] = df['registration_date'].dt.strftime('%Y-%m')
year_month_df = df.groupby(['year_month']).size().reset_index(name='counts')
pivot_table_df = year_month_df.pivot(index='year_month', columns='year', values='counts')
最后使用matplotlib或seaborn等工具进行可视化展示,例如:
import matplotlib.pyplot as plt
import seaborn as sns
plt.figure(figsize=(10,6))
sns.lineplot(data=pivot_table_df)
plt.xlabel('Month')
plt.ylabel('Number of registrations')
plt.title('Yearly registration trend')
plt.show()
start_date = pd.to_datetime('2019-01-01', format='%Y-%m-%d')
end_date = pd.to_datetime('2020-12-31', format='%Y-%m-%d')
selected_df = df[(df['registration_date'] >= start_date) & (df['registration_date'] <= end_date)]
然后可以根据地域、渠道、来源等维度进行新用户数量、转化率等分析,例如:
plt.figure(figsize=(10,6))
sns.countplot(data=selected_df, x='region')
plt.xlabel('Region')
plt.ylabel('Number of registrations')
plt.title('New registrations by region')
plt.show()
或者:
conversion_df = selected_df.groupby(['channel'])['is_active'].agg(['count', 'mean']).reset_index()
conversion_df.columns = ['Channel', 'Number of registrations', 'Conversion rate']
conversion_df.sort_values(by='Number of registrations', ascending=False, inplace=True)
plt.figure(figsize=(10,6))
sns.barplot(data=conversion_df, x='Conversion rate', y='Channel')
plt.xlabel('Conversion rate')
plt.ylabel('Channel')
plt.title('New registration conversion rates by channel')
plt.show()
以上是我能提供的解决方案,希望能对您有所帮助。