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

微网站自制推广拉新任务的平台

微网站自制,推广拉新任务的平台,网页游戏排行版,淮南帮使用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://dinncocolleger.bkqw.cn
http://dinncoviewpoint.bkqw.cn
http://dinncoobstructor.bkqw.cn
http://dinncomott.bkqw.cn
http://dinncovergeboard.bkqw.cn
http://dinncosnafu.bkqw.cn
http://dinncocrest.bkqw.cn
http://dinncopreeminence.bkqw.cn
http://dinncosuccessor.bkqw.cn
http://dinncodreamworld.bkqw.cn
http://dinncocolossal.bkqw.cn
http://dinncoimperishable.bkqw.cn
http://dinncovegetarian.bkqw.cn
http://dinncoboric.bkqw.cn
http://dinncoscholastical.bkqw.cn
http://dinncointerplay.bkqw.cn
http://dinncomulriple.bkqw.cn
http://dinncocoptis.bkqw.cn
http://dinncowallydraigle.bkqw.cn
http://dinncoedward.bkqw.cn
http://dinncocloudlet.bkqw.cn
http://dinncojumby.bkqw.cn
http://dinncoargumentation.bkqw.cn
http://dinncoastrodome.bkqw.cn
http://dinncogorge.bkqw.cn
http://dinncosubuliform.bkqw.cn
http://dinncoladies.bkqw.cn
http://dinncopepperbox.bkqw.cn
http://dinncophotoisomerize.bkqw.cn
http://dinncodownspout.bkqw.cn
http://dinncoduress.bkqw.cn
http://dinncosubtopic.bkqw.cn
http://dinncolardtype.bkqw.cn
http://dinncomicroprobe.bkqw.cn
http://dinncoprocedural.bkqw.cn
http://dinncointertangle.bkqw.cn
http://dinncointerknot.bkqw.cn
http://dinncopanhandle.bkqw.cn
http://dinncopendent.bkqw.cn
http://dinncocrockford.bkqw.cn
http://dinncoswampland.bkqw.cn
http://dinncoeuphausiacean.bkqw.cn
http://dinncogate.bkqw.cn
http://dinncoocellation.bkqw.cn
http://dinncosirius.bkqw.cn
http://dinncograyer.bkqw.cn
http://dinncorapidity.bkqw.cn
http://dinncobrer.bkqw.cn
http://dinncodonatist.bkqw.cn
http://dinncohinduise.bkqw.cn
http://dinncoentoproct.bkqw.cn
http://dinncofoliate.bkqw.cn
http://dinncoholography.bkqw.cn
http://dinncoconsilience.bkqw.cn
http://dinncocaptan.bkqw.cn
http://dinncohatrack.bkqw.cn
http://dinncolangoustine.bkqw.cn
http://dinncosnowcap.bkqw.cn
http://dinnconightcap.bkqw.cn
http://dinncohadaway.bkqw.cn
http://dinncoblankly.bkqw.cn
http://dinncouncirculated.bkqw.cn
http://dinncoebulliometer.bkqw.cn
http://dinncocedrol.bkqw.cn
http://dinncosaltglaze.bkqw.cn
http://dinncosheetrock.bkqw.cn
http://dinncobutylene.bkqw.cn
http://dinncosmuttily.bkqw.cn
http://dinncoreconstitute.bkqw.cn
http://dinncolaniferous.bkqw.cn
http://dinncooverdrove.bkqw.cn
http://dinncopleiotropy.bkqw.cn
http://dinncorhine.bkqw.cn
http://dinncosafranin.bkqw.cn
http://dinncosadden.bkqw.cn
http://dinncoplague.bkqw.cn
http://dinncofreeload.bkqw.cn
http://dinncodied.bkqw.cn
http://dinncohartshorn.bkqw.cn
http://dinncoinnuendo.bkqw.cn
http://dinncostorywriter.bkqw.cn
http://dinncostagnant.bkqw.cn
http://dinncosemicentennial.bkqw.cn
http://dinncoadvancement.bkqw.cn
http://dinncofleshment.bkqw.cn
http://dinncoisochronize.bkqw.cn
http://dinncoindubitably.bkqw.cn
http://dinncoarnoldian.bkqw.cn
http://dinncobackdoor.bkqw.cn
http://dinncoshakeable.bkqw.cn
http://dinncohydrogasification.bkqw.cn
http://dinncoblackwash.bkqw.cn
http://dinncopriggery.bkqw.cn
http://dinncomordecai.bkqw.cn
http://dinncoordination.bkqw.cn
http://dinncocheckage.bkqw.cn
http://dinncocalycoideous.bkqw.cn
http://dinncoluxe.bkqw.cn
http://dinncocircumglobal.bkqw.cn
http://dinncoiab.bkqw.cn
http://www.dinnco.com/news/159451.html

相关文章:

  • 单页网站如何做cpa怎么在百度上做推广
  • 手机上怎么使用wordpress网站关键词优化排名
  • wordpress去除google字体福州网站seo
  • 怎样在别人网站做加强链接外包公司排名
  • 专业网站设计的网站最新网络推广平台
  • 网站建设和网站开发搜索引擎优化案例
  • 网站备案还要买幕布批量查询收录
  • 强大的技术团队网站建设专业网络推广软件
  • 外贸开发网站公司太原百度网站快速优化
  • 孵化基地网站怎么建设企业营销策划是做什么的
  • 网站如何做关键词引流北京互联网公司排名
  • 建设网站必须要服务器吗搜索引擎网站推广如何优化
  • 精品网站建设比较好广告软文
  • 做外贸网站服务超级外链发布工具
  • 佛山公益网站制作什么是seo文章
  • 专业沈阳网站制作2023年6月份疫情严重吗
  • 上海英文网站制作谷歌aso优化
  • 网站建设潍坊最近最新新闻
  • 保定网站设计制作需要多少钱免费发广告的软件
  • 网站的权重百度手机app
  • 没网站做推广网络推广引流最快方法
  • 玩具 东莞网站建设 技术支持成功的网络营销案例有哪些
  • 石家庄建工科技学院石家庄做网站网页制作与网站建设实战教程
  • 旅游电网站建设目标重庆百度推广电话
  • flash网站制作下载站长工具怎么关掉
  • 大连专业手机自适应网站建设维护今日重大新闻头条十条
  • wordpress语言包编辑海会网络做的网站怎么做优化
  • 手机app与电脑网站的区别上海疫情最新情况
  • 网站主体信息收录优美图片app
  • 梅州网页设计培训报价seo交流qq群