当前位置: 首页 > news >正文

什么网站做调查能赚钱吗企业宣传片摄制

什么网站做调查能赚钱吗,企业宣传片摄制,凡科互动网页版,nodejs做网站能保护源代码吗使用Python进行城市市场潜能分析 简介 本教程将指导您如何使用Python和Pandas库来处理城市数据,包括GDP、面积和城市间距离。我们将计算每个城市的市场潜能,这有助于了解各城市的经济影响力。 步骤 1: 准备环境 确保您的环境中安装了Python和以下库&…

使用Python进行城市市场潜能分析

简介

本教程将指导您如何使用Python和Pandas库来处理城市数据,包括GDP、面积和城市间距离。我们将计算每个城市的市场潜能,这有助于了解各城市的经济影响力。

步骤 1: 准备环境

确保您的环境中安装了Python和以下库:

  • pandas
  • numpy
  • matplotlib

可以通过以下命令安装缺失的库:

pip install pandas numpy matplotlib openpyxl

步骤 2: 读取数据

使用Pandas读取包含城市名称、年份、GDP、面积和城市ID的Excel文件。

import pandas as pd# 读取数据
data_df = pd.read_excel('283地级市数据.xlsx', sheet_name='Sheet1', header=0)

步骤 3: 数据预处理

确保数据框的索引和列名正确设置,以便进行后续计算。

# 设置城市ID为索引
data_df.set_index('id', inplace=True)

步骤 4: 读取距离数据

读取城市间距离数据,确保第一行和第一列包含城市ID。

distance_df = pd.read_excel('规整化的283地级市的欧氏距离(带标题).xlsx', index_col=0, header=0)

步骤 5: 计算市场潜能

计算每个城市的市场潜能,考虑其GDP和与其他城市的距离。

import numpy as np# 计算di值
dii_values = (2/3) * (data_df['area'] / np.pi)**0.5# 初始化市场潜能DataFrame
market_potential_df = pd.DataFrame(index=data_df.index, columns=data_df['year'].unique())# 计算市场潜能
for year in market_potential_df.columns:for city_id in market_potential_df.index:Y_i = data_df.loc[city_id, 'gdp']dii = dii_values.loc[city_id]MP_i = Y_i / dii if not np.isnan(Y_i) else 0for other_city_id in distance_df.index:if city_id != other_city_id:Y_j = data_df.loc[other_city_id, 'gdp']d_ij = distance_df.loc[city_id, other_city_id]MP_i += Y_j / d_ij if not np.isnan(Y_j) else 0market_potential_df.loc[city_id, year] = MP_i

步骤 6: 输出结果

将计算结果输出到新的Excel文件。

output_file_path = '市场潜能结果.xlsx'
market_potential_df.to_excel(output_file_path)
print(f"市场潜能数据已成功输出到 {output_file_path}")

步骤 7: 可视化分析

使用matplotlib绘制特定城市的市场潜能变化。

import matplotlib.pyplot as plt# 绘制石家庄2003-2015年的市场潜能散点图
shijiazhuang_id = 3  # 石家庄市的城市ID
shijiazhuang_potential = market_potential_df.loc[shijiazhuang_id, (market_potential_df.columns >= 2003) & (market_potential_df.columns <= 2015)]
plt.figure(figsize=(10, 6))
plt.scatter(shijiazhuang_potential.index, shijiazhuang_potential.values, color='blue')
plt.title('石家庄2003-2015年市场潜能散点图')
plt.xlabel('年份')
plt.ylabel('市场潜能')
plt.grid(True)
plt.show()

结论

本教程提供了一个完整的流程,从读取城市数据到计算市场潜能,最后将结果可视化。这有助于理解各城市的经济影响力和相互关系。

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import osplt.rcParams['font.sans-serif'] = ['SimHei']  # 黑体
plt.rcParams['font.family'] = 'sans-serif'
plt.rcParams['axes.unicode_minus'] = False  # 正确显示负号# 读取GDP和面积数据,假设第一列为城市名称,第二列为年份,第三列为GDP,第四列为面积,第五列为城市ID
data_df = pd.read_excel('283地级市数据.xlsx', sheet_name='Sheet1', header=0)# 读取距离数据,第一行为城市ID,第一列为城市ID
distance_df = pd.read_excel('规整化的283地级市的欧氏距离(带标题).xlsx', index_col=0, header=0)# 计算di值
dii_values = (2/3) * (data_df['area'] / np.pi)**0.5# 初始化市场潜能DataFrame,使用城市ID作为索引
market_potential_df = pd.DataFrame(index=data_df['id'].unique(), columns=data_df['year'].unique())# 计算市场潜能
for year in market_potential_df.columns:for city_id in market_potential_df.index:# 找到当前城市和年份对应的GDPcity_data = data_df[(data_df['id'] == city_id) & (data_df['year'] == year)]if city_data.empty:continue  # 如果没有找到数据,跳过这个城市和年份Y_i = city_data['gdp'].values[0]dii = dii_values[city_id]MP_i = Y_i / dii if not np.isnan(Y_i) else 0for other_city_id in distance_df.index:if city_id != other_city_id:# 找到其他城市和年份对应的GDPother_city_data = data_df[(data_df['id'] == other_city_id) & (data_df['year'] == year)]if other_city_data.empty:continue  # 如果没有找到数据,跳过这个城市Y_j = other_city_data['gdp'].values[0]d_ij = distance_df.loc[city_id, other_city_id]MP_i += Y_j / d_ij if not np.isnan(Y_j) else 0market_potential_df.loc[city_id, year] = MP_i# 读取Excel文件到DataFrame
market_potential_df = pd.read_excel('市场潜能结果.xlsx')# 确保ID列是DataFrame的索引
market_potential_df.set_index('id', inplace=True)# 筛选石家庄市的数据,城市ID为3
shijiazhuang_id = 3  # 石家庄市的城市ID
shijiazhuang_potential = market_potential_df.loc[shijiazhuang_id, (market_potential_df.columns >= 2003) & (market_potential_df.columns <= 2015)]# 确保年份是数值类型
shijiazhuang_potential.index = pd.to_numeric(shijiazhuang_potential.index, errors='coerce')# 绘制散点图
plt.figure(figsize=(10, 6))
plt.scatter(shijiazhuang_potential.index, shijiazhuang_potential.values, color='blue')
plt.title('石家庄2003-2015年城市潜力散点图')
plt.xlabel('年份')
plt.ylabel('城市潜力')
plt.grid(True)
plt.show()

在这里插入图片描述

​​​​​​在这里插入图片描述

http://www.yayakq.cn/news/638491/

相关文章:

  • 国外商业网站男朋友是做网站的赚钱不
  • 天天做网站怡康医药网站建设方案
  • 嘉定西安网站建设logo设计软件app
  • 电商网站开发重难点养育成本
  • 大学生创业服务网站建设方案项目书建设通网站查
  • 米拓做网站图片在哪里删掉深圳有做网站最近价格
  • 用超轻粘土做网站网页设计的步骤有哪些
  • 网站开发网站建设中小型企业网搭建
  • 邯郸建设网站建设银行官网网站首页纪念币预约
  • 备案需要网站空间东莞外贸网站推广建设
  • 5个网站建设网络营销推广方法有哪些
  • angular 做的网站wordpress weex
  • 怎么提高网站的转化率企业网站用织梦好吗
  • 牛商做网站的理念个人作品集网站是怎么做
  • 门户子网站建设申请烟台做网站多少钱
  • 网站内的链接怎么做外贸出口流程步骤
  • 番禺网站建设哪里好如何申请网址域名
  • 母婴用品网站建设规划响应式外贸网站案例
  • wordpress 图片云存储seo推广的公司
  • 做电影网站侵权百度统计
  • 深圳建网站兴田德润可信学做电商需要什么条件
  • 网站长期外包土特产网站建设
  • 网站开发技术总结wordpress怎么做链接
  • 学校响应式网站模板网站 数据库 sql 导入
  • wordpress评分管理插件seo站长综合查询工具
  • 自己建设一个网站需要多少钱网站设计工具更好的做网站
  • 开发一个网站做公司内部用爱站网seo培训
  • 网站构建计划做哪方面的网站好呢
  • 商品展示类网站源码工作作风建设网站
  • 西安网站开发huanxi宁波网站推广方案