backup: 2025-03-05
|
@ -1,8 +0,0 @@
|
|||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="jdk" jdkName="crawler" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -1,70 +0,0 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredPackages">
|
||||
<value>
|
||||
<list size="40">
|
||||
<item index="0" class="java.lang.String" itemvalue="mysqlclient" />
|
||||
<item index="1" class="java.lang.String" itemvalue="tiktoken" />
|
||||
<item index="2" class="java.lang.String" itemvalue="PyJWT" />
|
||||
<item index="3" class="java.lang.String" itemvalue="greenlet" />
|
||||
<item index="4" class="java.lang.String" itemvalue="mypy-extensions" />
|
||||
<item index="5" class="java.lang.String" itemvalue="python-dotenv" />
|
||||
<item index="6" class="java.lang.String" itemvalue="astroid" />
|
||||
<item index="7" class="java.lang.String" itemvalue="feedparser" />
|
||||
<item index="8" class="java.lang.String" itemvalue="requests-oauthlib" />
|
||||
<item index="9" class="java.lang.String" itemvalue="docx2txt" />
|
||||
<item index="10" class="java.lang.String" itemvalue="tomlkit" />
|
||||
<item index="11" class="java.lang.String" itemvalue="djangorestframework-simplejwt" />
|
||||
<item index="12" class="java.lang.String" itemvalue="langchain" />
|
||||
<item index="13" class="java.lang.String" itemvalue="certifi" />
|
||||
<item index="14" class="java.lang.String" itemvalue="arxiv" />
|
||||
<item index="15" class="java.lang.String" itemvalue="djangorestframework" />
|
||||
<item index="16" class="java.lang.String" itemvalue="PyMuPDF" />
|
||||
<item index="17" class="java.lang.String" itemvalue="pydantic" />
|
||||
<item index="18" class="java.lang.String" itemvalue="dj-database-url" />
|
||||
<item index="19" class="java.lang.String" itemvalue="django-simpleui" />
|
||||
<item index="20" class="java.lang.String" itemvalue="wrapt" />
|
||||
<item index="21" class="java.lang.String" itemvalue="cryptography" />
|
||||
<item index="22" class="java.lang.String" itemvalue="pypdf" />
|
||||
<item index="23" class="java.lang.String" itemvalue="dj-rest-auth" />
|
||||
<item index="24" class="java.lang.String" itemvalue="attrs" />
|
||||
<item index="25" class="java.lang.String" itemvalue="lazy-object-proxy" />
|
||||
<item index="26" class="java.lang.String" itemvalue="openai" />
|
||||
<item index="27" class="java.lang.String" itemvalue="regex" />
|
||||
<item index="28" class="java.lang.String" itemvalue="platformdirs" />
|
||||
<item index="29" class="java.lang.String" itemvalue="typing-inspect" />
|
||||
<item index="30" class="java.lang.String" itemvalue="Django" />
|
||||
<item index="31" class="java.lang.String" itemvalue="pylint" />
|
||||
<item index="32" class="java.lang.String" itemvalue="charset-normalizer" />
|
||||
<item index="33" class="java.lang.String" itemvalue="aiohttp" />
|
||||
<item index="34" class="java.lang.String" itemvalue="multidict" />
|
||||
<item index="35" class="java.lang.String" itemvalue="django-allauth" />
|
||||
<item index="36" class="java.lang.String" itemvalue="isort" />
|
||||
<item index="37" class="java.lang.String" itemvalue="yarl" />
|
||||
<item index="38" class="java.lang.String" itemvalue="pytz" />
|
||||
<item index="39" class="java.lang.String" itemvalue="aiosignal" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<option name="ignoredErrors">
|
||||
<list>
|
||||
<option value="N802" />
|
||||
<option value="N806" />
|
||||
<option value="N801" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredIdentifiers">
|
||||
<list>
|
||||
<option value="PyQt5.QtWidgets.clicked.*" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
|
@ -1,6 +0,0 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.9 (Warbler)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="crawler" project-jdk-type="Python SDK" />
|
||||
</project>
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/20231220 Cong.iml" filepath="$PROJECT_DIR$/.idea/20231220 Cong.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,124 +0,0 @@
|
|||
import time
|
||||
|
||||
import selenium.common.exceptions
|
||||
from selenium import webdriver
|
||||
from bs4 import BeautifulSoup
|
||||
import pandas as pd
|
||||
|
||||
# 创建一个Chrome浏览器实例
|
||||
driver = webdriver.Chrome(executable_path=r'/Users/fallcity/Vvvvv/Coding/tools/chromedriver')
|
||||
|
||||
df = pd.DataFrame(columns=['站点', '标题', '链接'], )
|
||||
|
||||
|
||||
# 重庆市人民政府
|
||||
def get_all_links_cq():
|
||||
url = 'https://www.cq.gov.cn/cqgovsearch/search.html?searchWord=%E6%99%BA%E6%85%A7%E7%A4%BE%E5%8C%BA&tenantId=7&configTenantId=&dataTypeId=7&sign=d46b7b1d-937f-4c52-e9af-0dbac183bf18&areaCode='
|
||||
driver.get(url)
|
||||
time.sleep(2)
|
||||
times = 1
|
||||
while times <= 15:
|
||||
try:
|
||||
print(f"正在爬取重庆市人民政府相关文本 第{times}页")
|
||||
next_page_btn = driver.find_element_by_class_name('layui-laypage-next')
|
||||
page_source = driver.page_source
|
||||
soup = BeautifulSoup(page_source, 'html.parser')
|
||||
lst = soup.find(class_='basic_result_content')
|
||||
links = lst.find_all('a')
|
||||
for link in links:
|
||||
df.loc[len(df)] = ['重庆市人民政府', link.text.strip(), link['href']]
|
||||
print(links)
|
||||
time.sleep(1)
|
||||
next_page_btn.click()
|
||||
time.sleep(1)
|
||||
times += 1
|
||||
except selenium.common.exceptions.NoSuchElementException or selenium.common.exceptions.TimeoutException:
|
||||
break
|
||||
|
||||
# 发改委
|
||||
def get_all_links_ndrc():
|
||||
url = 'https://so.ndrc.gov.cn/s?qt=%E6%99%BA%E6%85%A7%E7%A4%BE%E5%8C%BA&siteCode=bm04000007&tab=all&toolsStatus=1'
|
||||
driver.get(url)
|
||||
time.sleep(2)
|
||||
times = 1
|
||||
while times <= 7:
|
||||
print(f"正在爬取中华人民共和国国家发展和改革委员会相关文本 第{times}页")
|
||||
next_page_btn = driver.find_elements_by_class_name('next')[-1]
|
||||
page_source = driver.page_source
|
||||
soup = BeautifulSoup(page_source, 'html.parser')
|
||||
lst = soup.find(class_='content fl')
|
||||
links = lst.find_all('a')
|
||||
for link in links:
|
||||
try:
|
||||
if 'javascript' not in link['href']:
|
||||
df.loc[len(df)] = ['中华人民共和国国家发展和改革委员会', link.text.strip(), link['href']]
|
||||
except KeyError:
|
||||
pass
|
||||
print(links)
|
||||
next_page_btn.click()
|
||||
time.sleep(1)
|
||||
times += 1
|
||||
|
||||
|
||||
# 住建部
|
||||
def get_all_links_mohurd():
|
||||
url = 'https://www.mohurd.gov.cn/ess/?ty=a&query=%E6%99%BA%E6%85%A7%E7%A4%BE%E5%8C%BA&ukl=&uka=&ukf=%E6%99%BA%E6%85%A7%E7%A4%BE%E5%8C%BA&ukt=&sl=&ts=&te=&upg=1'
|
||||
driver.get(url)
|
||||
time.sleep(2)
|
||||
times = 1
|
||||
while times <= 15:
|
||||
try:
|
||||
print(f"正在爬取中华人民共和国住房和城乡建设部相关文本 第{times}页")
|
||||
next_page_btn = driver.find_element_by_class_name('next')
|
||||
page_source = driver.page_source
|
||||
soup = BeautifulSoup(page_source, 'html.parser')
|
||||
lst = soup.find(class_='result-list')
|
||||
links = lst.find_all('a')
|
||||
for link in links:
|
||||
try:
|
||||
if 'javascript' not in link['href']:
|
||||
df.loc[len(df)] = ['中华人民共和国住房和城乡建设部', link.text.strip(), link['href']]
|
||||
except KeyError:
|
||||
pass
|
||||
print(links)
|
||||
next_page_btn.click()
|
||||
time.sleep(1)
|
||||
times += 1
|
||||
except selenium.common.exceptions.NoSuchElementException:
|
||||
break
|
||||
|
||||
|
||||
def get_all_links_gov():
|
||||
url = 'https://sousuo.www.gov.cn/sousuo/search.shtml?code=17da70961a7&dataTypeId=107&searchWord=%E6%99%BA%E6%85%A7%E7%A4%BE%E5%8C%BA'
|
||||
driver.get(url)
|
||||
time.sleep(2)
|
||||
times = 1
|
||||
while times <= 3:
|
||||
try:
|
||||
print(f"正在爬取中华人民共和国中央人民政府相关文本 第{times}页")
|
||||
next_page_btn = driver.find_element_by_class_name('next')
|
||||
page_source = driver.page_source
|
||||
soup = BeautifulSoup(page_source, 'html.parser')
|
||||
lst = soup.find(class_='left js_basic_result_left')
|
||||
links = lst.find_all('a')
|
||||
for link in links:
|
||||
try:
|
||||
if 'javascript' not in link['href'] and link['href'] != 'url':
|
||||
df.loc[len(df)] = ['中华人民共和国中央人民政府', link.text.strip(), link['href']]
|
||||
except KeyError:
|
||||
pass
|
||||
print(links)
|
||||
next_page_btn.click()
|
||||
time.sleep(1)
|
||||
times += 1
|
||||
except selenium.common.exceptions.NoSuchElementException:
|
||||
break
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
get_all_links_cq()
|
||||
get_all_links_ndrc()
|
||||
get_all_links_mohurd()
|
||||
get_all_links_gov()
|
||||
driver.quit() # 安全退出
|
||||
df.to_excel('智慧社区文本.xlsx', index=False)
|
|
@ -1,57 +0,0 @@
|
|||
import time
|
||||
|
||||
import pandas as pd
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from selenium import webdriver
|
||||
|
||||
driver = webdriver.Chrome(executable_path=r'/Users/fallcity/Vvvvv/Coding/tools/chromedriver')
|
||||
|
||||
|
||||
def crawl_website(site: str, url: str):
|
||||
print(f"正在爬取 {site}: {url}")
|
||||
|
||||
driver.get(url)
|
||||
page_source = driver.page_source
|
||||
soup = BeautifulSoup(page_source, 'html.parser')
|
||||
|
||||
try:
|
||||
if ".doc" in url:
|
||||
return ""
|
||||
elif site == '重庆市人民政府':
|
||||
div = soup.find('div', class_='view TRS_UEDITOR trs_paper_default trs_word')
|
||||
if div:
|
||||
text = div.get_text(strip=True)
|
||||
return text
|
||||
elif site == '中华人民共和国国家发展和改革委员会':
|
||||
div = soup.find('div', class_='TRS_Editor')
|
||||
if div:
|
||||
text = div.get_text(strip=True)
|
||||
return text
|
||||
elif site == '中华人民共和国住房和城乡建设部':
|
||||
div = soup.find('div', class_='editor-content')
|
||||
if div:
|
||||
text = div.get_text(strip=True)
|
||||
return text
|
||||
elif site == '中华人民共和国中央人民政府':
|
||||
div = soup.find('div', id='UCAP-CONTENT')
|
||||
if div:
|
||||
text = div.get_text(strip=True)
|
||||
return text
|
||||
except TimeoutError:
|
||||
exit(1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
df = pd.read_excel('智慧社区文本.xlsx', engine='openpyxl')
|
||||
df['文本内容'] = ""
|
||||
for index, row in df.iterrows():
|
||||
# 调用get_text函数获取文本内容
|
||||
text_content = crawl_website(row['站点'], row['链接'])
|
||||
# 将文本内容填入'文本内容'列
|
||||
df.at[index, '文本内容'] = text_content
|
||||
# 休眠2秒
|
||||
time.sleep(2)
|
||||
df = df.drop_duplicates(subset=['文本内容'])
|
||||
df.to_excel('智慧社区文本.xlsx', index=False)
|
||||
driver.quit()
|
|
@ -1,54 +0,0 @@
|
|||
import pandas as pd
|
||||
import jieba
|
||||
from collections import Counter
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib
|
||||
from wordcloud import WordCloud
|
||||
|
||||
# 设置字体 MAC
|
||||
matplotlib.rcParams['font.sans-serif'] = ['Arial Unicode MS']
|
||||
# 设置字体 Windows
|
||||
# matplotlib.rcParams['font.sans-serif'] = ['SimHei']
|
||||
matplotlib.rcParams['axes.unicode_minus'] = False # 正确显示负号
|
||||
|
||||
|
||||
# 读取Excel文件
|
||||
df = pd.read_excel('智慧社区文本.xlsx')
|
||||
|
||||
# 读取停用词表
|
||||
with open('stopwords.txt', 'r', encoding='utf-8') as f:
|
||||
stop_words = set([line.strip() for line in f.readlines()])
|
||||
|
||||
# 合并所有文本内容到一个字符串
|
||||
all_text = ' '.join(df['文本内容'].dropna())
|
||||
|
||||
# 使用jieba进行中文分词
|
||||
words = jieba.cut(all_text)
|
||||
|
||||
|
||||
# 过滤停用词并统计词频
|
||||
filtered_words = [word for word in words if word not in stop_words and len(word) > 1]
|
||||
word_counts = Counter(filtered_words)
|
||||
|
||||
# 可视化最常见的词
|
||||
most_common_words = word_counts.most_common(20)
|
||||
words, counts = zip(*most_common_words)
|
||||
|
||||
plt.figure(figsize=(10, 8))
|
||||
plt.barh(words, counts)
|
||||
plt.xlabel('词频')
|
||||
plt.title('词频分析')
|
||||
plt.gca().invert_yaxis() # 反转y轴,使得最高的条形图在上方
|
||||
plt.savefig('词频分析.png')
|
||||
plt.show()
|
||||
|
||||
# 创建词云图
|
||||
wordcloud = WordCloud(font_path='苹方-简.ttf',width=800, height=600,
|
||||
background_color='white').generate_from_frequencies(word_counts)
|
||||
|
||||
plt.figure(figsize=(10, 8))
|
||||
plt.imshow(wordcloud, interpolation='bilinear')
|
||||
plt.axis('off') # 关闭坐标轴
|
||||
plt.title('词云图')
|
||||
plt.savefig('词云图.png')
|
||||
plt.show()
|
|
@ -1,748 +0,0 @@
|
|||
$
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
?
|
||||
_
|
||||
“
|
||||
”
|
||||
、
|
||||
。
|
||||
《
|
||||
》
|
||||
一
|
||||
一些
|
||||
一何
|
||||
一切
|
||||
一则
|
||||
一方面
|
||||
一旦
|
||||
一来
|
||||
一样
|
||||
一般
|
||||
一转眼
|
||||
万一
|
||||
上
|
||||
上下
|
||||
下
|
||||
不
|
||||
不仅
|
||||
不但
|
||||
不光
|
||||
不单
|
||||
不只
|
||||
不外乎
|
||||
不如
|
||||
不妨
|
||||
不尽
|
||||
不尽然
|
||||
不得
|
||||
不怕
|
||||
不惟
|
||||
不成
|
||||
不拘
|
||||
不料
|
||||
不是
|
||||
不比
|
||||
不然
|
||||
不特
|
||||
不独
|
||||
不管
|
||||
不至于
|
||||
不若
|
||||
不论
|
||||
不过
|
||||
不问
|
||||
与
|
||||
与其
|
||||
与其说
|
||||
与否
|
||||
与此同时
|
||||
且
|
||||
且不说
|
||||
且说
|
||||
两者
|
||||
个
|
||||
个别
|
||||
临
|
||||
为
|
||||
为了
|
||||
为什么
|
||||
为何
|
||||
为止
|
||||
为此
|
||||
为着
|
||||
乃
|
||||
乃至
|
||||
乃至于
|
||||
么
|
||||
之
|
||||
之一
|
||||
之所以
|
||||
之类
|
||||
乌乎
|
||||
乎
|
||||
乘
|
||||
也
|
||||
也好
|
||||
也罢
|
||||
了
|
||||
二来
|
||||
于
|
||||
于是
|
||||
于是乎
|
||||
云云
|
||||
云尔
|
||||
些
|
||||
亦
|
||||
人
|
||||
人们
|
||||
人家
|
||||
什么
|
||||
什么样
|
||||
今
|
||||
介于
|
||||
仍
|
||||
仍旧
|
||||
从
|
||||
从此
|
||||
从而
|
||||
他
|
||||
他人
|
||||
他们
|
||||
以
|
||||
以上
|
||||
以为
|
||||
以便
|
||||
以免
|
||||
以及
|
||||
以故
|
||||
以期
|
||||
以来
|
||||
以至
|
||||
以至于
|
||||
以致
|
||||
们
|
||||
任
|
||||
任何
|
||||
任凭
|
||||
似的
|
||||
但
|
||||
但凡
|
||||
但是
|
||||
何
|
||||
何以
|
||||
何况
|
||||
何处
|
||||
何时
|
||||
余外
|
||||
作为
|
||||
你
|
||||
你们
|
||||
使
|
||||
使得
|
||||
例如
|
||||
依
|
||||
依据
|
||||
依照
|
||||
便于
|
||||
俺
|
||||
俺们
|
||||
倘
|
||||
倘使
|
||||
倘或
|
||||
倘然
|
||||
倘若
|
||||
借
|
||||
假使
|
||||
假如
|
||||
假若
|
||||
傥然
|
||||
像
|
||||
儿
|
||||
先不先
|
||||
光是
|
||||
全体
|
||||
全部
|
||||
兮
|
||||
关于
|
||||
其
|
||||
其一
|
||||
其中
|
||||
其二
|
||||
其他
|
||||
其余
|
||||
其它
|
||||
其次
|
||||
具体地说
|
||||
具体说来
|
||||
兼之
|
||||
内
|
||||
再
|
||||
再其次
|
||||
再则
|
||||
再有
|
||||
再者
|
||||
再者说
|
||||
再说
|
||||
冒
|
||||
冲
|
||||
况且
|
||||
几
|
||||
几时
|
||||
凡
|
||||
凡是
|
||||
凭
|
||||
凭借
|
||||
出于
|
||||
出来
|
||||
分别
|
||||
则
|
||||
则甚
|
||||
别
|
||||
别人
|
||||
别处
|
||||
别是
|
||||
别的
|
||||
别管
|
||||
别说
|
||||
到
|
||||
前后
|
||||
前此
|
||||
前者
|
||||
加之
|
||||
加以
|
||||
即
|
||||
即令
|
||||
即使
|
||||
即便
|
||||
即如
|
||||
即或
|
||||
即若
|
||||
却
|
||||
去
|
||||
又
|
||||
又及
|
||||
及
|
||||
及其
|
||||
及至
|
||||
反之
|
||||
反而
|
||||
反过来
|
||||
反过来说
|
||||
受到
|
||||
另
|
||||
另一方面
|
||||
另外
|
||||
另悉
|
||||
只
|
||||
只当
|
||||
只怕
|
||||
只是
|
||||
只有
|
||||
只消
|
||||
只要
|
||||
只限
|
||||
叫
|
||||
叮咚
|
||||
可
|
||||
可以
|
||||
可是
|
||||
可见
|
||||
各
|
||||
各个
|
||||
各位
|
||||
各种
|
||||
各自
|
||||
同
|
||||
同时
|
||||
后
|
||||
后者
|
||||
向
|
||||
向使
|
||||
向着
|
||||
吓
|
||||
吗
|
||||
否则
|
||||
吧
|
||||
吧哒
|
||||
吱
|
||||
呀
|
||||
呃
|
||||
呕
|
||||
呗
|
||||
呜
|
||||
呜呼
|
||||
呢
|
||||
呵
|
||||
呵呵
|
||||
呸
|
||||
呼哧
|
||||
咋
|
||||
和
|
||||
咚
|
||||
咦
|
||||
咧
|
||||
咱
|
||||
咱们
|
||||
咳
|
||||
哇
|
||||
哈
|
||||
哈哈
|
||||
哉
|
||||
哎
|
||||
哎呀
|
||||
哎哟
|
||||
哗
|
||||
哟
|
||||
哦
|
||||
哩
|
||||
哪
|
||||
哪个
|
||||
哪些
|
||||
哪儿
|
||||
哪天
|
||||
哪年
|
||||
哪怕
|
||||
哪样
|
||||
哪边
|
||||
哪里
|
||||
哼
|
||||
哼唷
|
||||
唉
|
||||
唯有
|
||||
啊
|
||||
啐
|
||||
啥
|
||||
啦
|
||||
啪达
|
||||
啷当
|
||||
喂
|
||||
喏
|
||||
喔唷
|
||||
喽
|
||||
嗡
|
||||
嗡嗡
|
||||
嗬
|
||||
嗯
|
||||
嗳
|
||||
嘎
|
||||
嘎登
|
||||
嘘
|
||||
嘛
|
||||
嘻
|
||||
嘿
|
||||
嘿嘿
|
||||
因
|
||||
因为
|
||||
因了
|
||||
因此
|
||||
因着
|
||||
因而
|
||||
固然
|
||||
在
|
||||
在下
|
||||
在于
|
||||
地
|
||||
基于
|
||||
处在
|
||||
多
|
||||
多么
|
||||
多少
|
||||
大
|
||||
大家
|
||||
她
|
||||
她们
|
||||
好
|
||||
如
|
||||
如上
|
||||
如上所述
|
||||
如下
|
||||
如何
|
||||
如其
|
||||
如同
|
||||
如是
|
||||
如果
|
||||
如此
|
||||
如若
|
||||
始而
|
||||
孰料
|
||||
孰知
|
||||
宁
|
||||
宁可
|
||||
宁愿
|
||||
宁肯
|
||||
它
|
||||
它们
|
||||
对
|
||||
对于
|
||||
对待
|
||||
对方
|
||||
对比
|
||||
将
|
||||
小
|
||||
尔
|
||||
尔后
|
||||
尔尔
|
||||
尚且
|
||||
就
|
||||
就是
|
||||
就是了
|
||||
就是说
|
||||
就算
|
||||
就要
|
||||
尽
|
||||
尽管
|
||||
尽管如此
|
||||
岂但
|
||||
己
|
||||
已
|
||||
已矣
|
||||
巴
|
||||
巴巴
|
||||
并
|
||||
并且
|
||||
并非
|
||||
庶乎
|
||||
庶几
|
||||
开外
|
||||
开始
|
||||
归
|
||||
归齐
|
||||
当
|
||||
当地
|
||||
当然
|
||||
当着
|
||||
彼
|
||||
彼时
|
||||
彼此
|
||||
往
|
||||
待
|
||||
很
|
||||
得
|
||||
得了
|
||||
怎
|
||||
怎么
|
||||
怎么办
|
||||
怎么样
|
||||
怎奈
|
||||
怎样
|
||||
总之
|
||||
总的来看
|
||||
总的来说
|
||||
总的说来
|
||||
总而言之
|
||||
恰恰相反
|
||||
您
|
||||
惟其
|
||||
慢说
|
||||
我
|
||||
我们
|
||||
或
|
||||
或则
|
||||
或是
|
||||
或曰
|
||||
或者
|
||||
截至
|
||||
所
|
||||
所以
|
||||
所在
|
||||
所幸
|
||||
所有
|
||||
才
|
||||
才能
|
||||
打
|
||||
打从
|
||||
把
|
||||
抑或
|
||||
拿
|
||||
按
|
||||
按照
|
||||
换句话说
|
||||
换言之
|
||||
据
|
||||
据此
|
||||
接着
|
||||
故
|
||||
故此
|
||||
故而
|
||||
旁人
|
||||
无
|
||||
无宁
|
||||
无论
|
||||
既
|
||||
既往
|
||||
既是
|
||||
既然
|
||||
时候
|
||||
是
|
||||
是以
|
||||
是的
|
||||
曾
|
||||
替
|
||||
替代
|
||||
最
|
||||
有
|
||||
有些
|
||||
有关
|
||||
有及
|
||||
有时
|
||||
有的
|
||||
望
|
||||
朝
|
||||
朝着
|
||||
本
|
||||
本人
|
||||
本地
|
||||
本着
|
||||
本身
|
||||
来
|
||||
来着
|
||||
来自
|
||||
来说
|
||||
极了
|
||||
果然
|
||||
果真
|
||||
某
|
||||
某个
|
||||
某些
|
||||
某某
|
||||
根据
|
||||
欤
|
||||
正值
|
||||
正如
|
||||
正巧
|
||||
正是
|
||||
此
|
||||
此地
|
||||
此处
|
||||
此外
|
||||
此时
|
||||
此次
|
||||
此间
|
||||
毋宁
|
||||
每
|
||||
每当
|
||||
比
|
||||
比及
|
||||
比如
|
||||
比方
|
||||
没奈何
|
||||
沿
|
||||
沿着
|
||||
漫说
|
||||
焉
|
||||
然则
|
||||
然后
|
||||
然而
|
||||
照
|
||||
照着
|
||||
犹且
|
||||
犹自
|
||||
甚且
|
||||
甚么
|
||||
甚或
|
||||
甚而
|
||||
甚至
|
||||
甚至于
|
||||
用
|
||||
用来
|
||||
由
|
||||
由于
|
||||
由是
|
||||
由此
|
||||
由此可见
|
||||
的
|
||||
的确
|
||||
的话
|
||||
直到
|
||||
相对而言
|
||||
省得
|
||||
看
|
||||
眨眼
|
||||
着
|
||||
着呢
|
||||
矣
|
||||
矣乎
|
||||
矣哉
|
||||
离
|
||||
竟而
|
||||
第
|
||||
等
|
||||
等到
|
||||
等等
|
||||
简言之
|
||||
管
|
||||
类如
|
||||
紧接着
|
||||
纵
|
||||
纵令
|
||||
纵使
|
||||
纵然
|
||||
经
|
||||
经过
|
||||
结果
|
||||
给
|
||||
继之
|
||||
继后
|
||||
继而
|
||||
综上所述
|
||||
罢了
|
||||
者
|
||||
而
|
||||
而且
|
||||
而况
|
||||
而后
|
||||
而外
|
||||
而已
|
||||
而是
|
||||
而言
|
||||
能
|
||||
能否
|
||||
腾
|
||||
自
|
||||
自个儿
|
||||
自从
|
||||
自各儿
|
||||
自后
|
||||
自家
|
||||
自己
|
||||
自打
|
||||
自身
|
||||
至
|
||||
至于
|
||||
至今
|
||||
至若
|
||||
致
|
||||
般的
|
||||
若
|
||||
若夫
|
||||
若是
|
||||
若果
|
||||
若非
|
||||
莫不然
|
||||
莫如
|
||||
莫若
|
||||
虽
|
||||
虽则
|
||||
虽然
|
||||
虽说
|
||||
被
|
||||
要
|
||||
要不
|
||||
要不是
|
||||
要不然
|
||||
要么
|
||||
要是
|
||||
譬喻
|
||||
譬如
|
||||
让
|
||||
许多
|
||||
论
|
||||
设使
|
||||
设或
|
||||
设若
|
||||
诚如
|
||||
诚然
|
||||
该
|
||||
说来
|
||||
诸
|
||||
诸位
|
||||
诸如
|
||||
谁
|
||||
谁人
|
||||
谁料
|
||||
谁知
|
||||
贼死
|
||||
赖以
|
||||
赶
|
||||
起
|
||||
起见
|
||||
趁
|
||||
趁着
|
||||
越是
|
||||
距
|
||||
跟
|
||||
较
|
||||
较之
|
||||
边
|
||||
过
|
||||
还
|
||||
还是
|
||||
还有
|
||||
还要
|
||||
这
|
||||
这一来
|
||||
这个
|
||||
这么
|
||||
这么些
|
||||
这么样
|
||||
这么点儿
|
||||
这些
|
||||
这会儿
|
||||
这儿
|
||||
这就是说
|
||||
这时
|
||||
这样
|
||||
这次
|
||||
这般
|
||||
这边
|
||||
这里
|
||||
进而
|
||||
连
|
||||
连同
|
||||
逐步
|
||||
通过
|
||||
遵循
|
||||
遵照
|
||||
那
|
||||
那个
|
||||
那么
|
||||
那么些
|
||||
那么样
|
||||
那些
|
||||
那会儿
|
||||
那儿
|
||||
那时
|
||||
那样
|
||||
那般
|
||||
那边
|
||||
那里
|
||||
都
|
||||
鄙人
|
||||
鉴于
|
||||
针对
|
||||
阿
|
||||
除
|
||||
除了
|
||||
除外
|
||||
除开
|
||||
除此之外
|
||||
除非
|
||||
随
|
||||
随后
|
||||
随时
|
||||
随着
|
||||
难道说
|
||||
非但
|
||||
非徒
|
||||
非特
|
||||
非独
|
||||
靠
|
||||
顺
|
||||
顺着
|
||||
首先
|
||||
!
|
||||
,
|
||||
:
|
||||
;
|
||||
?
|
||||
通讯员
|
||||
记者
|
Before Width: | Height: | Size: 391 KiB |
Before Width: | Height: | Size: 28 KiB |
|
@ -1,54 +0,0 @@
|
|||
import time
|
||||
|
||||
import pandas as pd
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from selenium import webdriver
|
||||
|
||||
driver = webdriver.Chrome(executable_path=r'/Users/fallcity/Vvvvv/Coding/tools/chromedriver')
|
||||
|
||||
|
||||
def crawl_website(site: str, url: str):
|
||||
print(f"正在爬取 {site}: {url}")
|
||||
|
||||
driver.get(url)
|
||||
page_source = driver.page_source
|
||||
soup = BeautifulSoup(page_source, 'html.parser')
|
||||
|
||||
try:
|
||||
if site == '重庆市人民政府':
|
||||
div = soup.find('div', class_='view TRS_UEDITOR trs_paper_default trs_word')
|
||||
if div:
|
||||
text = div.get_text(strip=True)
|
||||
return text
|
||||
elif site == '中华人民共和国国家发展和改革委员会':
|
||||
div = soup.find('div', class_='TRS_Editor')
|
||||
if div:
|
||||
text = div.get_text(strip=True)
|
||||
return text
|
||||
elif site == '中华人民共和国住房和城乡建设部':
|
||||
div = soup.find('div', class_='editor-content')
|
||||
if div:
|
||||
text = div.get_text(strip=True)
|
||||
return text
|
||||
elif site == '中华人民共和国中央人民政府':
|
||||
div = soup.find('div', id='UCAP-CONTENT')
|
||||
if div:
|
||||
text = div.get_text(strip=True)
|
||||
return text
|
||||
except TimeoutError:
|
||||
exit(1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
df = pd.read_excel('智慧社区文本.xlsx', engine='openpyxl')
|
||||
df['文本内容'] = ""
|
||||
for index, row in df.iterrows():
|
||||
# 调用get_text函数获取文本内容
|
||||
text_content = crawl_website(row['站点'], row['链接'])
|
||||
# 将文本内容填入'文本内容'列
|
||||
df.at[index, '文本内容'] = text_content
|
||||
# 休眠2秒
|
||||
time.sleep(2)
|
||||
df.to_excel('updated_file.xlsx', index=False)
|
||||
driver.quit()
|
|
@ -1,748 +0,0 @@
|
|||
$
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
?
|
||||
_
|
||||
“
|
||||
”
|
||||
、
|
||||
。
|
||||
《
|
||||
》
|
||||
一
|
||||
一些
|
||||
一何
|
||||
一切
|
||||
一则
|
||||
一方面
|
||||
一旦
|
||||
一来
|
||||
一样
|
||||
一般
|
||||
一转眼
|
||||
万一
|
||||
上
|
||||
上下
|
||||
下
|
||||
不
|
||||
不仅
|
||||
不但
|
||||
不光
|
||||
不单
|
||||
不只
|
||||
不外乎
|
||||
不如
|
||||
不妨
|
||||
不尽
|
||||
不尽然
|
||||
不得
|
||||
不怕
|
||||
不惟
|
||||
不成
|
||||
不拘
|
||||
不料
|
||||
不是
|
||||
不比
|
||||
不然
|
||||
不特
|
||||
不独
|
||||
不管
|
||||
不至于
|
||||
不若
|
||||
不论
|
||||
不过
|
||||
不问
|
||||
与
|
||||
与其
|
||||
与其说
|
||||
与否
|
||||
与此同时
|
||||
且
|
||||
且不说
|
||||
且说
|
||||
两者
|
||||
个
|
||||
个别
|
||||
临
|
||||
为
|
||||
为了
|
||||
为什么
|
||||
为何
|
||||
为止
|
||||
为此
|
||||
为着
|
||||
乃
|
||||
乃至
|
||||
乃至于
|
||||
么
|
||||
之
|
||||
之一
|
||||
之所以
|
||||
之类
|
||||
乌乎
|
||||
乎
|
||||
乘
|
||||
也
|
||||
也好
|
||||
也罢
|
||||
了
|
||||
二来
|
||||
于
|
||||
于是
|
||||
于是乎
|
||||
云云
|
||||
云尔
|
||||
些
|
||||
亦
|
||||
人
|
||||
人们
|
||||
人家
|
||||
什么
|
||||
什么样
|
||||
今
|
||||
介于
|
||||
仍
|
||||
仍旧
|
||||
从
|
||||
从此
|
||||
从而
|
||||
他
|
||||
他人
|
||||
他们
|
||||
以
|
||||
以上
|
||||
以为
|
||||
以便
|
||||
以免
|
||||
以及
|
||||
以故
|
||||
以期
|
||||
以来
|
||||
以至
|
||||
以至于
|
||||
以致
|
||||
们
|
||||
任
|
||||
任何
|
||||
任凭
|
||||
似的
|
||||
但
|
||||
但凡
|
||||
但是
|
||||
何
|
||||
何以
|
||||
何况
|
||||
何处
|
||||
何时
|
||||
余外
|
||||
作为
|
||||
你
|
||||
你们
|
||||
使
|
||||
使得
|
||||
例如
|
||||
依
|
||||
依据
|
||||
依照
|
||||
便于
|
||||
俺
|
||||
俺们
|
||||
倘
|
||||
倘使
|
||||
倘或
|
||||
倘然
|
||||
倘若
|
||||
借
|
||||
假使
|
||||
假如
|
||||
假若
|
||||
傥然
|
||||
像
|
||||
儿
|
||||
先不先
|
||||
光是
|
||||
全体
|
||||
全部
|
||||
兮
|
||||
关于
|
||||
其
|
||||
其一
|
||||
其中
|
||||
其二
|
||||
其他
|
||||
其余
|
||||
其它
|
||||
其次
|
||||
具体地说
|
||||
具体说来
|
||||
兼之
|
||||
内
|
||||
再
|
||||
再其次
|
||||
再则
|
||||
再有
|
||||
再者
|
||||
再者说
|
||||
再说
|
||||
冒
|
||||
冲
|
||||
况且
|
||||
几
|
||||
几时
|
||||
凡
|
||||
凡是
|
||||
凭
|
||||
凭借
|
||||
出于
|
||||
出来
|
||||
分别
|
||||
则
|
||||
则甚
|
||||
别
|
||||
别人
|
||||
别处
|
||||
别是
|
||||
别的
|
||||
别管
|
||||
别说
|
||||
到
|
||||
前后
|
||||
前此
|
||||
前者
|
||||
加之
|
||||
加以
|
||||
即
|
||||
即令
|
||||
即使
|
||||
即便
|
||||
即如
|
||||
即或
|
||||
即若
|
||||
却
|
||||
去
|
||||
又
|
||||
又及
|
||||
及
|
||||
及其
|
||||
及至
|
||||
反之
|
||||
反而
|
||||
反过来
|
||||
反过来说
|
||||
受到
|
||||
另
|
||||
另一方面
|
||||
另外
|
||||
另悉
|
||||
只
|
||||
只当
|
||||
只怕
|
||||
只是
|
||||
只有
|
||||
只消
|
||||
只要
|
||||
只限
|
||||
叫
|
||||
叮咚
|
||||
可
|
||||
可以
|
||||
可是
|
||||
可见
|
||||
各
|
||||
各个
|
||||
各位
|
||||
各种
|
||||
各自
|
||||
同
|
||||
同时
|
||||
后
|
||||
后者
|
||||
向
|
||||
向使
|
||||
向着
|
||||
吓
|
||||
吗
|
||||
否则
|
||||
吧
|
||||
吧哒
|
||||
吱
|
||||
呀
|
||||
呃
|
||||
呕
|
||||
呗
|
||||
呜
|
||||
呜呼
|
||||
呢
|
||||
呵
|
||||
呵呵
|
||||
呸
|
||||
呼哧
|
||||
咋
|
||||
和
|
||||
咚
|
||||
咦
|
||||
咧
|
||||
咱
|
||||
咱们
|
||||
咳
|
||||
哇
|
||||
哈
|
||||
哈哈
|
||||
哉
|
||||
哎
|
||||
哎呀
|
||||
哎哟
|
||||
哗
|
||||
哟
|
||||
哦
|
||||
哩
|
||||
哪
|
||||
哪个
|
||||
哪些
|
||||
哪儿
|
||||
哪天
|
||||
哪年
|
||||
哪怕
|
||||
哪样
|
||||
哪边
|
||||
哪里
|
||||
哼
|
||||
哼唷
|
||||
唉
|
||||
唯有
|
||||
啊
|
||||
啐
|
||||
啥
|
||||
啦
|
||||
啪达
|
||||
啷当
|
||||
喂
|
||||
喏
|
||||
喔唷
|
||||
喽
|
||||
嗡
|
||||
嗡嗡
|
||||
嗬
|
||||
嗯
|
||||
嗳
|
||||
嘎
|
||||
嘎登
|
||||
嘘
|
||||
嘛
|
||||
嘻
|
||||
嘿
|
||||
嘿嘿
|
||||
因
|
||||
因为
|
||||
因了
|
||||
因此
|
||||
因着
|
||||
因而
|
||||
固然
|
||||
在
|
||||
在下
|
||||
在于
|
||||
地
|
||||
基于
|
||||
处在
|
||||
多
|
||||
多么
|
||||
多少
|
||||
大
|
||||
大家
|
||||
她
|
||||
她们
|
||||
好
|
||||
如
|
||||
如上
|
||||
如上所述
|
||||
如下
|
||||
如何
|
||||
如其
|
||||
如同
|
||||
如是
|
||||
如果
|
||||
如此
|
||||
如若
|
||||
始而
|
||||
孰料
|
||||
孰知
|
||||
宁
|
||||
宁可
|
||||
宁愿
|
||||
宁肯
|
||||
它
|
||||
它们
|
||||
对
|
||||
对于
|
||||
对待
|
||||
对方
|
||||
对比
|
||||
将
|
||||
小
|
||||
尔
|
||||
尔后
|
||||
尔尔
|
||||
尚且
|
||||
就
|
||||
就是
|
||||
就是了
|
||||
就是说
|
||||
就算
|
||||
就要
|
||||
尽
|
||||
尽管
|
||||
尽管如此
|
||||
岂但
|
||||
己
|
||||
已
|
||||
已矣
|
||||
巴
|
||||
巴巴
|
||||
并
|
||||
并且
|
||||
并非
|
||||
庶乎
|
||||
庶几
|
||||
开外
|
||||
开始
|
||||
归
|
||||
归齐
|
||||
当
|
||||
当地
|
||||
当然
|
||||
当着
|
||||
彼
|
||||
彼时
|
||||
彼此
|
||||
往
|
||||
待
|
||||
很
|
||||
得
|
||||
得了
|
||||
怎
|
||||
怎么
|
||||
怎么办
|
||||
怎么样
|
||||
怎奈
|
||||
怎样
|
||||
总之
|
||||
总的来看
|
||||
总的来说
|
||||
总的说来
|
||||
总而言之
|
||||
恰恰相反
|
||||
您
|
||||
惟其
|
||||
慢说
|
||||
我
|
||||
我们
|
||||
或
|
||||
或则
|
||||
或是
|
||||
或曰
|
||||
或者
|
||||
截至
|
||||
所
|
||||
所以
|
||||
所在
|
||||
所幸
|
||||
所有
|
||||
才
|
||||
才能
|
||||
打
|
||||
打从
|
||||
把
|
||||
抑或
|
||||
拿
|
||||
按
|
||||
按照
|
||||
换句话说
|
||||
换言之
|
||||
据
|
||||
据此
|
||||
接着
|
||||
故
|
||||
故此
|
||||
故而
|
||||
旁人
|
||||
无
|
||||
无宁
|
||||
无论
|
||||
既
|
||||
既往
|
||||
既是
|
||||
既然
|
||||
时候
|
||||
是
|
||||
是以
|
||||
是的
|
||||
曾
|
||||
替
|
||||
替代
|
||||
最
|
||||
有
|
||||
有些
|
||||
有关
|
||||
有及
|
||||
有时
|
||||
有的
|
||||
望
|
||||
朝
|
||||
朝着
|
||||
本
|
||||
本人
|
||||
本地
|
||||
本着
|
||||
本身
|
||||
来
|
||||
来着
|
||||
来自
|
||||
来说
|
||||
极了
|
||||
果然
|
||||
果真
|
||||
某
|
||||
某个
|
||||
某些
|
||||
某某
|
||||
根据
|
||||
欤
|
||||
正值
|
||||
正如
|
||||
正巧
|
||||
正是
|
||||
此
|
||||
此地
|
||||
此处
|
||||
此外
|
||||
此时
|
||||
此次
|
||||
此间
|
||||
毋宁
|
||||
每
|
||||
每当
|
||||
比
|
||||
比及
|
||||
比如
|
||||
比方
|
||||
没奈何
|
||||
沿
|
||||
沿着
|
||||
漫说
|
||||
焉
|
||||
然则
|
||||
然后
|
||||
然而
|
||||
照
|
||||
照着
|
||||
犹且
|
||||
犹自
|
||||
甚且
|
||||
甚么
|
||||
甚或
|
||||
甚而
|
||||
甚至
|
||||
甚至于
|
||||
用
|
||||
用来
|
||||
由
|
||||
由于
|
||||
由是
|
||||
由此
|
||||
由此可见
|
||||
的
|
||||
的确
|
||||
的话
|
||||
直到
|
||||
相对而言
|
||||
省得
|
||||
看
|
||||
眨眼
|
||||
着
|
||||
着呢
|
||||
矣
|
||||
矣乎
|
||||
矣哉
|
||||
离
|
||||
竟而
|
||||
第
|
||||
等
|
||||
等到
|
||||
等等
|
||||
简言之
|
||||
管
|
||||
类如
|
||||
紧接着
|
||||
纵
|
||||
纵令
|
||||
纵使
|
||||
纵然
|
||||
经
|
||||
经过
|
||||
结果
|
||||
给
|
||||
继之
|
||||
继后
|
||||
继而
|
||||
综上所述
|
||||
罢了
|
||||
者
|
||||
而
|
||||
而且
|
||||
而况
|
||||
而后
|
||||
而外
|
||||
而已
|
||||
而是
|
||||
而言
|
||||
能
|
||||
能否
|
||||
腾
|
||||
自
|
||||
自个儿
|
||||
自从
|
||||
自各儿
|
||||
自后
|
||||
自家
|
||||
自己
|
||||
自打
|
||||
自身
|
||||
至
|
||||
至于
|
||||
至今
|
||||
至若
|
||||
致
|
||||
般的
|
||||
若
|
||||
若夫
|
||||
若是
|
||||
若果
|
||||
若非
|
||||
莫不然
|
||||
莫如
|
||||
莫若
|
||||
虽
|
||||
虽则
|
||||
虽然
|
||||
虽说
|
||||
被
|
||||
要
|
||||
要不
|
||||
要不是
|
||||
要不然
|
||||
要么
|
||||
要是
|
||||
譬喻
|
||||
譬如
|
||||
让
|
||||
许多
|
||||
论
|
||||
设使
|
||||
设或
|
||||
设若
|
||||
诚如
|
||||
诚然
|
||||
该
|
||||
说来
|
||||
诸
|
||||
诸位
|
||||
诸如
|
||||
谁
|
||||
谁人
|
||||
谁料
|
||||
谁知
|
||||
贼死
|
||||
赖以
|
||||
赶
|
||||
起
|
||||
起见
|
||||
趁
|
||||
趁着
|
||||
越是
|
||||
距
|
||||
跟
|
||||
较
|
||||
较之
|
||||
边
|
||||
过
|
||||
还
|
||||
还是
|
||||
还有
|
||||
还要
|
||||
这
|
||||
这一来
|
||||
这个
|
||||
这么
|
||||
这么些
|
||||
这么样
|
||||
这么点儿
|
||||
这些
|
||||
这会儿
|
||||
这儿
|
||||
这就是说
|
||||
这时
|
||||
这样
|
||||
这次
|
||||
这般
|
||||
这边
|
||||
这里
|
||||
进而
|
||||
连
|
||||
连同
|
||||
逐步
|
||||
通过
|
||||
遵循
|
||||
遵照
|
||||
那
|
||||
那个
|
||||
那么
|
||||
那么些
|
||||
那么样
|
||||
那些
|
||||
那会儿
|
||||
那儿
|
||||
那时
|
||||
那样
|
||||
那般
|
||||
那边
|
||||
那里
|
||||
都
|
||||
鄙人
|
||||
鉴于
|
||||
针对
|
||||
阿
|
||||
除
|
||||
除了
|
||||
除外
|
||||
除开
|
||||
除此之外
|
||||
除非
|
||||
随
|
||||
随后
|
||||
随时
|
||||
随着
|
||||
难道说
|
||||
非但
|
||||
非徒
|
||||
非特
|
||||
非独
|
||||
靠
|
||||
顺
|
||||
顺着
|
||||
首先
|
||||
!
|
||||
,
|
||||
:
|
||||
;
|
||||
?
|
||||
通讯员
|
||||
记者
|
|
@ -1 +0,0 @@
|
|||
.idea
|
|
@ -1,34 +0,0 @@
|
|||
## 如何运行
|
||||
|
||||
0. 环境与依赖:
|
||||
- python 3.7
|
||||
- tensorflow 2.0.0b0
|
||||
- pillow(PIL) 4.3.0
|
||||
1. 下载数据集:[The EMNIST Dataset](https://www.nist.gov/itl/products-and-services/emnist-dataset)
|
||||
2. 解压数据集,选取其中的
|
||||
- emnist-letters-train-labels-idx1-ubyte.gz
|
||||
- emnist-letters-train-images-idx3-ubyte.gz
|
||||
- emnist-letters-test-labels-idx1-ubyte.gz
|
||||
- emnist-letters-test-images-idx3-ubyte.gz
|
||||
复制到 `data_set_emnist_letters` 目录中(已放入)
|
||||
3. 运行 `src/letters/letter_train.py` 开始模型训练
|
||||
4. 运行 `src/letters/letter_predict.py` ,对 `english_images` 下的所有图片进行识别,并逐一显示结果
|
||||
|
||||
## 附 字符编码表(UTF-8)
|
||||
|
||||
| **字符** | **编码10进制** | **编码16进制** | **Unicode编码10进制** | **Unicode编码16进制** |
|
||||
| -------- | -------------- | -------------- | --------------------- | --------------------- |
|
||||
| a | 97 | 61 | 97 | 61 |
|
||||
| b | 98 | 62 | 98 | 62 |
|
||||
| c | 99 | 63 | 99 | 63 |
|
||||
| d | 100 | 64 | 100 | 64 |
|
||||
| e | 101 | 65 | 101 | 65 |
|
||||
| f | 102 | 66 | 102 | 66 |
|
||||
| z | 122 | 7A | 122 | 7A |
|
||||
| A | 65 | 41 | 65 | 41 |
|
||||
| B | 66 | 42 | 66 | 42 |
|
||||
| C | 67 | 43 | 67 | 43 |
|
||||
| D | 68 | 44 | 68 | 44 |
|
||||
| E | 69 | 45 | 69 | 45 |
|
||||
| F | 70 | 46 | 70 | 46 |
|
||||
| Z | 90 | 5A | 90 | 5A |
|
|
@ -1,26 +0,0 @@
|
|||
1 65 97
|
||||
2 66 98
|
||||
3 67 99
|
||||
4 68 100
|
||||
5 69 101
|
||||
6 70 102
|
||||
7 71 103
|
||||
8 72 104
|
||||
9 73 105
|
||||
10 74 106
|
||||
11 75 107
|
||||
12 76 108
|
||||
13 77 109
|
||||
14 78 110
|
||||
15 79 111
|
||||
16 80 112
|
||||
17 81 113
|
||||
18 82 114
|
||||
19 83 115
|
||||
20 84 116
|
||||
21 85 117
|
||||
22 86 118
|
||||
23 87 119
|
||||
24 88 120
|
||||
25 89 121
|
||||
26 90 122
|
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 9.0 KiB |
Before Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 1017 B |
Before Width: | Height: | Size: 4.5 KiB |
|
@ -1,2 +0,0 @@
|
|||
model_checkpoint_path: "cp-0005.ckpt"
|
||||
all_model_checkpoint_paths: "cp-0005.ckpt"
|
|
@ -1,76 +0,0 @@
|
|||
import tensorflow as tf
|
||||
import numpy as np
|
||||
import os as os
|
||||
|
||||
from PIL import Image
|
||||
from src.letters.letter_train import CNN
|
||||
from src.utils.visualize import *
|
||||
|
||||
'''
|
||||
python 3.9.10
|
||||
tensorflow 2.0.0b0
|
||||
pillow(PIL) 4.3.0
|
||||
'''
|
||||
|
||||
|
||||
class Predict(object):
|
||||
|
||||
def __init__(self):
|
||||
latest = tf.train.latest_checkpoint('./ckpt')
|
||||
self.cnn = CNN()
|
||||
# 恢复网络权重
|
||||
self.cnn.model.load_weights(latest)
|
||||
|
||||
def predict(self, image_path):
|
||||
# 读取图片并转换为灰度模式,即将RGB通道合为一个通道,对这个单通道的数据进行操作
|
||||
img = Image.open(image_path).convert('L')
|
||||
# 预处理,统一转换为28*28大小
|
||||
img = prepare_image(img)
|
||||
# reshape()改变数组的结构,并且原始数据不发生变化
|
||||
# 将这个灰度图片作为一个数组,转换为28大组、28小组、每小组元素个数为1的数组
|
||||
# / 255 表示每个数都除以255,将每个数都压缩到0-1之间
|
||||
img = np.reshape(img, (28, 28, 1)) / 255
|
||||
# 数组的每个数被1减去,并且数组升一维,是为了符合模型的维度
|
||||
x = np.array([1 - img])
|
||||
|
||||
# 开始根据模型预测
|
||||
y = self.cnn.model.predict(x)
|
||||
|
||||
# 因为x只传入了一张图片,取y[0]即可
|
||||
# np.argmax()取得最大值的下标,即代表的数字
|
||||
print(image_path)
|
||||
print(np.argmax(y[0]))
|
||||
print('\t-> 这个图片写的是:', get_mapping(np.argmax(y[0]), with_type="letters"))
|
||||
# 可视化的方式展示图片
|
||||
show_pred_result(image_path, get_mapping(np.argmax(y[0]), with_type="letters"))
|
||||
|
||||
|
||||
def prepare_image(img: Image) -> Image:
|
||||
"""
|
||||
将待预测的图片进行预处理:
|
||||
水平翻转、逆时针旋转90度并统一缩放到28*28px。
|
||||
|
||||
这是因为,EMNIST中的数据集中参与训练的图片,
|
||||
是经过水平反转并顺时针旋转90度的,
|
||||
所以在预测的时候也要对应地变换一下。
|
||||
(所以EMNIST为什么要这么处理图片呢?)
|
||||
:param img:
|
||||
:return: Image
|
||||
"""
|
||||
return img \
|
||||
.transpose(Image.FLIP_LEFT_RIGHT) \
|
||||
.transpose(Image.ROTATE_90) \
|
||||
.resize((28, 28), Image.ANTIALIAS)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
"""
|
||||
开始预测
|
||||
"""
|
||||
image_dir = '../../english_images/'
|
||||
# cwd = os.getcwd()
|
||||
files = os.listdir(image_dir)
|
||||
# 遍历批量导入预测文件夹内的所有图片
|
||||
app = Predict()
|
||||
for image in files:
|
||||
app.predict(image_dir + image)
|
|
@ -1,130 +0,0 @@
|
|||
import os
|
||||
import tensorflow as tf
|
||||
from keras import layers, models
|
||||
from src.utils.load_emnist import *
|
||||
|
||||
'''
|
||||
python 3.7
|
||||
tensorflow 2.0.0b0
|
||||
'''
|
||||
|
||||
"""
|
||||
配置项
|
||||
"""
|
||||
config = {
|
||||
# 训练好的模型存放路径
|
||||
'check_path': "./ckpt/cp-{epoch:04d}.ckpt",
|
||||
# 类别数
|
||||
'class_num': 27,
|
||||
# 数据集位置
|
||||
'data_sets': [
|
||||
'./../../data_set_emnist_letters/emnist-letters-train-labels-idx1-ubyte.gz',
|
||||
'./../../data_set_emnist_letters/emnist-letters-train-images-idx3-ubyte.gz',
|
||||
'./../../data_set_emnist_letters/emnist-letters-test-labels-idx1-ubyte.gz',
|
||||
'./../../data_set_emnist_letters/emnist-letters-test-images-idx3-ubyte.gz']
|
||||
}
|
||||
|
||||
class CNN(object):
|
||||
def __init__(self):
|
||||
self.model = self.model()
|
||||
|
||||
@staticmethod
|
||||
def model():
|
||||
"""
|
||||
LetNet模型,测试准确度在94左右
|
||||
:return: model
|
||||
"""
|
||||
model = models.Sequential()
|
||||
# 第1层卷积:卷积核大小为3*3,32个,28*28为待训练图片的大小,激活函数选用relu
|
||||
# input_shape=(28, 28, 1) 输入层的维度
|
||||
# 此处三个数分别代表图片的长、宽、颜色深度(图片已经转化为灰度图像,所以颜色深度是1)
|
||||
model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)))
|
||||
# 池化层,减少参数(降维)和计算量,尽可能无损地提取主要特征,提高模型的适应能力
|
||||
# 参数是沿(垂直,水平)方向缩小比例的因数。(2, 2)会把输入张量的两个维度都缩小一半
|
||||
model.add(layers.MaxPooling2D((2, 2)))
|
||||
# 第2层卷积:卷积核大小为3*3,64个
|
||||
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
|
||||
# 池化层
|
||||
model.add(layers.MaxPooling2D((2, 2)))
|
||||
# 第3层卷积:卷积核大小为3*3,64个
|
||||
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
|
||||
|
||||
"""
|
||||
模型的后半部分,是定义输出张量的。
|
||||
layers.Flatten会将三维的张量转为一维的向量。
|
||||
展开前张量的维度是(3, 3, 64) ,转为一维(576)的向量后,
|
||||
紧接着使用layers.Dense层,构造了2层全连接层,
|
||||
逐步地将一维向量的位数从28*28=576变为64,再变为27。
|
||||
"""
|
||||
|
||||
# 将上一层的输出降到一维,即“扁平化”。(从卷积层到全连接层的过渡)
|
||||
model.add(layers.Flatten())
|
||||
# 后半部分相当于是构建了一个隐藏层为64,输入层为28*28=576,输出层为27的普通的神经网络
|
||||
model.add(layers.Dense(64, activation='relu'))
|
||||
# 输出层,27代表26个英文字母+1
|
||||
# 为什么加1?因为0号不用,26个英文字母,所以需要27个
|
||||
model.add(layers.Dense(config['class_num'], activation=tf.nn.softmax, name='predictions'))
|
||||
# 打印这个模型的总体参数
|
||||
model.summary()
|
||||
return model
|
||||
|
||||
|
||||
class DataSourceEMnist(object):
|
||||
"""
|
||||
获取数据集
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
files = config['data_sets']
|
||||
|
||||
# 读取数据集
|
||||
train_labels = read_idx1(files[0])
|
||||
train_images, train_images_num = read_idx3(files[1])
|
||||
test_labels = read_idx1(files[2])
|
||||
test_images, test_images_num = read_idx3(files[3])
|
||||
|
||||
# reshape()中的第一个参数传入训练集(测试集)的大小,下同。
|
||||
train_images = train_images.reshape((train_images_num, 28, 28, 1))
|
||||
test_images = test_images.reshape((test_images_num, 28, 28, 1))
|
||||
|
||||
# 像素值映射到 0 - 1 之间
|
||||
train_images, test_images = train_images / 255.0, test_images / 255.0
|
||||
|
||||
self.train_images, self.train_labels = train_images, train_labels
|
||||
self.test_images, self.test_labels = test_images, test_labels
|
||||
|
||||
|
||||
class Train:
|
||||
def __init__(self):
|
||||
self.cnn = CNN()
|
||||
self.data = DataSourceEMnist()
|
||||
|
||||
def train(self):
|
||||
check_path = config['check_path']
|
||||
# 保存模型到“检查点”,在后面完成训练模型时作为一个回调使用
|
||||
# 只能是 `keras.callbacks.Callback` 的实例
|
||||
# period 每隔5epoch保存一次
|
||||
save_model_cb = tf.keras.callbacks.ModelCheckpoint(
|
||||
check_path, save_weights_only=True, verbose=1, period=5)
|
||||
# 编译这个模型
|
||||
# optimizer: 优化器名或者优化器实例
|
||||
# loss: 损失函数名
|
||||
# metrics: 在训练和测试期间的模型评估标准
|
||||
self.cnn.model.compile(optimizer='adam',
|
||||
loss='sparse_categorical_crossentropy',
|
||||
metrics=['accuracy'])
|
||||
# 开始训练。
|
||||
# 前两个参数传入训练图片和标记的标签
|
||||
# epochs=5 训练五轮
|
||||
# callback 回调,表示训练完毕之后做什么。只能是 `keras.callbacks.Callback` 的实例
|
||||
self.cnn.model.fit(self.data.train_images, self.data.train_labels,
|
||||
epochs=5, callbacks=[save_model_cb])
|
||||
# 使用测试集对模型进行测试和评估
|
||||
test_loss, test_acc = self.cnn.model.evaluate(
|
||||
self.data.test_images, self.data.test_labels)
|
||||
print("准确率: %.4f,共测试了%d张图片 " % (test_acc, len(self.data.test_labels)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = Train()
|
||||
app.train()
|
|
@ -1,62 +0,0 @@
|
|||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import gzip
|
||||
|
||||
|
||||
def read_idx3(filename):
|
||||
"""
|
||||
读取gz格式的数据集图像部分,并返回
|
||||
|
||||
:param filename: extension name of the file is '.gz'
|
||||
:return: images data, shape -> num, rows, cols
|
||||
"""
|
||||
with gzip.open(filename) as fo:
|
||||
print('Reading images...')
|
||||
buf = fo.read()
|
||||
|
||||
offset = 0 # 偏移量
|
||||
# 首先获取的是这个数据集的头部数据,通常是元数据。
|
||||
# '>i' 表示顺序读取,并且数据类型为整数
|
||||
# 4 读4个单位
|
||||
# offset 偏移量
|
||||
# 返回的是一个数组,赋值给header
|
||||
header = np.frombuffer(buf, dtype='>i', count=4, offset=offset)
|
||||
print(header)
|
||||
magic_number, num_images, num_rows, num_cols = header
|
||||
# magic number 即幻数,意义不明,只是读取时需要占位所以声明了
|
||||
print("\tmagic number: {}, number of images: {}, number of rows: {}, number of columns: {}" \
|
||||
.format(magic_number, num_images, num_rows, num_cols))
|
||||
# 计算偏移量,以读取后续的内容
|
||||
# size = 数组长度
|
||||
# itemsize = 每个元素的大小
|
||||
# 因此乘起来就是跳过header的内容,读后续的内容
|
||||
offset += header.size * header.itemsize
|
||||
# 读取真正的数据。>B 表示是二进制数据
|
||||
data = np.frombuffer(buf, '>B', num_images * num_rows * num_cols, offset).reshape(
|
||||
(num_images, num_rows, num_cols))
|
||||
# .reshape 表示按传入的参数重新构造这个数组
|
||||
|
||||
return data, num_images
|
||||
|
||||
|
||||
def read_idx1(filename):
|
||||
"""
|
||||
读取gz格式的数据集标签部分,并返回
|
||||
|
||||
:param filename: extension name of the file is '.gz'
|
||||
:return: labels
|
||||
"""
|
||||
with gzip.open(filename) as fo:
|
||||
print('Reading labels...')
|
||||
buf = fo.read()
|
||||
|
||||
offset = 0
|
||||
header = np.frombuffer(buf, '>i', 2, offset)
|
||||
magic_number, num_labels = header
|
||||
print("\tmagic number: {}, number of labels: {}" \
|
||||
.format(magic_number, num_labels))
|
||||
|
||||
offset += header.size * header.itemsize
|
||||
|
||||
data = np.frombuffer(buf, '>B', num_labels, offset)
|
||||
return data
|
|
@ -1,81 +0,0 @@
|
|||
import cv2
|
||||
from PIL import Image
|
||||
import matplotlib as mpl
|
||||
|
||||
from src.utils.load_emnist import *
|
||||
|
||||
|
||||
def get_mapping(num, with_type='letters'):
|
||||
"""
|
||||
根据 mapping,由传入的 num 计算 UTF8 字符。详见 README.md
|
||||
:param num:
|
||||
:param with_type:
|
||||
:return:
|
||||
"""
|
||||
if with_type == 'byclass':
|
||||
if num <= 9:
|
||||
return chr(num + 48) # 数字
|
||||
elif num <= 35:
|
||||
return chr(num + 55) # 大写字母
|
||||
else:
|
||||
return chr(num + 61) # 小写字母
|
||||
elif with_type == 'letters':
|
||||
return chr(num + 64) + " / " + chr(num + 96) # 大写/小写字母
|
||||
elif with_type == 'digits':
|
||||
return chr(num + 96)
|
||||
else:
|
||||
return num
|
||||
|
||||
|
||||
def show_pred_result(path, result):
|
||||
"""
|
||||
可视化的方式展示图片和预测结果
|
||||
:param path: 图片路径
|
||||
:param result: 预测结果
|
||||
:return: None
|
||||
"""
|
||||
mpl.rcParams['font.sans-serif'] = ['SimHei'] # 中文字体支持
|
||||
img = Image.open(path)
|
||||
plt.figure(path) # 文件路径作窗口标题
|
||||
plt.axis('off') # 关闭坐标系显示
|
||||
plt.title("预测结果是:" + result)
|
||||
plt.imshow(img)
|
||||
plt.show()
|
||||
|
||||
|
||||
def show_data_set(images_data, num=1000):
|
||||
"""
|
||||
转换数据集中的内容并在窗口中展示
|
||||
:param images_data:
|
||||
:param num: 展示几个
|
||||
:return: None
|
||||
"""
|
||||
images = []
|
||||
img = []
|
||||
|
||||
for i in range(images_data.shape[0]):
|
||||
im = images_data[i]
|
||||
im = im.reshape(28, 28)
|
||||
if len(img) == 0:
|
||||
img = im
|
||||
else:
|
||||
# 横向组合
|
||||
img = np.hstack((img, im))
|
||||
|
||||
# 每行显示30个数字图片
|
||||
if img.shape[1] / 28 == 45:
|
||||
if len(images) == 0:
|
||||
images = img.copy()
|
||||
img = []
|
||||
else:
|
||||
# 纵向组合
|
||||
images = np.vstack((images, img))
|
||||
img = []
|
||||
|
||||
# 显示前 num 个
|
||||
if i == num:
|
||||
break
|
||||
|
||||
cv2.imshow('data_set_visualization', images)
|
||||
cv2.waitKey()
|
||||
cv2.destroyAllWindows()
|
|
@ -1,28 +0,0 @@
|
|||
from http import HTTPStatus
|
||||
from dashscope import Generation
|
||||
import dashscope
|
||||
|
||||
dashscope.api_key = 'sk-d986f58f46c74162a08655eaf37a8f80'
|
||||
|
||||
|
||||
def call_with_stream():
|
||||
messages = [
|
||||
{'role': 'user', 'content': '如何做西红柿炖牛腩?'}]
|
||||
responses = Generation.call("qwen-max",
|
||||
messages=messages,
|
||||
result_format='message', # 设置输出为'message'格式
|
||||
stream=True, # 设置输出方式为流式输出
|
||||
incremental_output=True # 增量式流式输出
|
||||
)
|
||||
for response in responses:
|
||||
if response.status_code == HTTPStatus.OK:
|
||||
print(response.output.choices[0]['message']['content'], end='')
|
||||
else:
|
||||
print('Request id: %s, Status code: %s, error code: %s, error message: %s' % (
|
||||
response.request_id, response.status_code,
|
||||
response.code, response.message
|
||||
))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
call_with_stream()
|
|
@ -1,69 +0,0 @@
|
|||
from collections import deque
|
||||
|
||||
|
||||
def bfs(capacities, target):
|
||||
# 初始化队列和访问过的状态集合
|
||||
queue = deque([(0, 0, 0)]) # 三个桶的初始状态
|
||||
visited = set([(0, 0, 0)])
|
||||
|
||||
# 操作步骤计数
|
||||
steps = 0
|
||||
|
||||
# 开始BFS搜索
|
||||
while queue:
|
||||
for _ in range(len(queue)):
|
||||
current_state = queue.popleft()
|
||||
a, b, c = current_state
|
||||
|
||||
# 如果找到目标状态
|
||||
if target in current_state:
|
||||
return steps
|
||||
|
||||
# 获取当前桶的容量
|
||||
A, B, C = capacities
|
||||
|
||||
# 对每一对桶进行操作
|
||||
next_states = [
|
||||
# 倒水操作:将水从一个桶倒入另一个桶
|
||||
# 从a桶倒到b桶
|
||||
(min(a + b, B), max(0, a + b - B), c),
|
||||
# 从a桶倒到c桶
|
||||
(min(a + c, C), b, max(0, a + c - C)),
|
||||
# 从b桶倒到a桶
|
||||
(min(a + b, A), max(0, a + b - A), c),
|
||||
# 从b桶倒到c桶
|
||||
(a, min(b + c, C), max(0, b + c - C)),
|
||||
# 从c桶倒到a桶
|
||||
(min(a + c, A), b, max(0, a + c - A)),
|
||||
# 从c桶倒到b桶
|
||||
(a, min(b + c, B), max(0, b + c - B)),
|
||||
# 清空每个桶
|
||||
(0, b, c),
|
||||
(a, 0, c),
|
||||
(a, b, 0),
|
||||
# 将每个桶填满
|
||||
(A, b, c),
|
||||
(a, B, c),
|
||||
(a, b, C)
|
||||
]
|
||||
|
||||
# 遍历所有新状态
|
||||
for state in next_states:
|
||||
if state not in visited:
|
||||
visited.add(state)
|
||||
queue.append(state)
|
||||
|
||||
# 增加操作次数
|
||||
steps += 1
|
||||
|
||||
return -1 # 如果找不到目标
|
||||
|
||||
|
||||
# 容器的容量
|
||||
capacities = [160, 119, 77]
|
||||
# 目标水量
|
||||
target = 76
|
||||
|
||||
# 求解最少操作次数
|
||||
result = bfs(capacities, target)
|
||||
print("最少操作次数:", result)
|
|
@ -1,8 +0,0 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.10" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -1,16 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CsvFileAttributes">
|
||||
<option name="attributeMap">
|
||||
<map>
|
||||
<entry key="/examples/macrodata.csv">
|
||||
<value>
|
||||
<Attribute>
|
||||
<option name="separator" value="," />
|
||||
</Attribute>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
|
@ -1,21 +0,0 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<option name="ignoredErrors">
|
||||
<list>
|
||||
<option value="N802" />
|
||||
<option value="N806" />
|
||||
<option value="N801" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredIdentifiers">
|
||||
<list>
|
||||
<option value="PyQt5.QtWidgets.clicked.*" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
|
@ -1,6 +0,0 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
|
||||
</project>
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/M301.iml" filepath="$PROJECT_DIR$/.idea/M301.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
BIN
M301/M301.zip
|
@ -1,204 +0,0 @@
|
|||
year,quarter,realgdp,realcons,realinv,realgovt,realdpi,cpi,m1,tbilrate,unemp,pop,infl,realint
|
||||
1959.0,1.0,2710.349,1707.4,286.898,470.045,1886.9,28.98,139.7,2.82,5.8,177.146,0.0,0.0
|
||||
1959.0,2.0,2778.801,1733.7,310.859,481.301,1919.7,29.15,141.7,3.08,5.1,177.83,2.34,0.74
|
||||
1959.0,3.0,2775.488,1751.8,289.226,491.26,1916.4,29.35,140.5,3.82,5.3,178.657,2.74,1.09
|
||||
1959.0,4.0,2785.204,1753.7,299.356,484.052,1931.3,29.37,140.0,4.33,5.6,179.386,0.27,4.06
|
||||
1960.0,1.0,2847.699,1770.5,331.722,462.199,1955.5,29.54,139.6,3.5,5.2,180.007,2.31,1.19
|
||||
1960.0,2.0,2834.39,1792.9,298.152,460.4,1966.1,29.55,140.2,2.68,5.2,180.671,0.14,2.55
|
||||
1960.0,3.0,2839.022,1785.8,296.375,474.676,1967.8,29.75,140.9,2.36,5.6,181.528,2.7,-0.34
|
||||
1960.0,4.0,2802.616,1788.2,259.764,476.434,1966.6,29.84,141.1,2.29,6.3,182.287,1.21,1.08
|
||||
1961.0,1.0,2819.264,1787.7,266.405,475.854,1984.5,29.81,142.1,2.37,6.8,182.992,-0.4,2.77
|
||||
1961.0,2.0,2872.005,1814.3,286.246,480.328,2014.4,29.92,142.9,2.29,7.0,183.691,1.47,0.81
|
||||
1961.0,3.0,2918.419,1823.1,310.227,493.828,2041.9,29.98,144.1,2.32,6.8,184.524,0.8,1.52
|
||||
1961.0,4.0,2977.83,1859.6,315.463,502.521,2082.0,30.04,145.2,2.6,6.2,185.242,0.8,1.8
|
||||
1962.0,1.0,3031.241,1879.4,334.271,520.96,2101.7,30.21,146.4,2.73,5.6,185.874,2.26,0.47
|
||||
1962.0,2.0,3064.709,1902.5,331.039,523.066,2125.2,30.22,146.5,2.78,5.5,186.538,0.13,2.65
|
||||
1962.0,3.0,3093.047,1917.9,336.962,538.838,2137.0,30.38,146.7,2.78,5.6,187.323,2.11,0.67
|
||||
1962.0,4.0,3100.563,1945.1,325.65,535.912,2154.6,30.44,148.3,2.87,5.5,188.013,0.79,2.08
|
||||
1963.0,1.0,3141.087,1958.2,343.721,522.917,2172.5,30.48,149.7,2.9,5.8,188.58,0.53,2.38
|
||||
1963.0,2.0,3180.447,1976.9,348.73,518.108,2193.1,30.69,151.3,3.03,5.7,189.242,2.75,0.29
|
||||
1963.0,3.0,3240.332,2003.8,360.102,546.893,2217.9,30.75,152.6,3.38,5.5,190.028,0.78,2.6
|
||||
1963.0,4.0,3264.967,2020.6,364.534,532.383,2254.6,30.94,153.7,3.52,5.6,190.668,2.46,1.06
|
||||
1964.0,1.0,3338.246,2060.5,379.523,529.686,2299.6,30.95,154.8,3.51,5.5,191.245,0.13,3.38
|
||||
1964.0,2.0,3376.587,2096.7,377.778,526.175,2362.1,31.02,156.8,3.47,5.2,191.889,0.9,2.57
|
||||
1964.0,3.0,3422.469,2135.2,386.754,522.008,2392.7,31.12,159.2,3.53,5.0,192.631,1.29,2.25
|
||||
1964.0,4.0,3431.957,2141.2,389.91,514.603,2420.4,31.28,160.7,3.76,5.0,193.223,2.05,1.71
|
||||
1965.0,1.0,3516.251,2188.8,429.145,508.006,2447.4,31.38,162.0,3.93,4.9,193.709,1.28,2.65
|
||||
1965.0,2.0,3563.96,2213.0,429.119,508.931,2474.5,31.58,163.1,3.84,4.7,194.303,2.54,1.3
|
||||
1965.0,3.0,3636.285,2251.0,444.444,529.446,2542.6,31.65,166.0,3.93,4.4,194.997,0.89,3.04
|
||||
1965.0,4.0,3724.014,2314.3,446.493,544.121,2594.1,31.88,169.1,4.35,4.1,195.539,2.9,1.46
|
||||
1966.0,1.0,3815.423,2348.5,484.244,556.593,2618.4,32.28,171.8,4.62,3.9,195.999,4.99,-0.37
|
||||
1966.0,2.0,3828.124,2354.5,475.408,571.371,2624.7,32.45,170.3,4.65,3.8,196.56,2.1,2.55
|
||||
1966.0,3.0,3853.301,2381.5,470.697,594.514,2657.8,32.85,171.2,5.23,3.8,197.207,4.9,0.33
|
||||
1966.0,4.0,3884.52,2391.4,472.957,599.528,2688.2,32.9,171.9,5.0,3.7,197.736,0.61,4.39
|
||||
1967.0,1.0,3918.74,2405.3,460.007,640.682,2728.4,33.1,174.2,4.22,3.8,198.206,2.42,1.8
|
||||
1967.0,2.0,3919.556,2438.1,440.393,631.43,2750.8,33.4,178.1,3.78,3.8,198.712,3.61,0.17
|
||||
1967.0,3.0,3950.826,2450.6,453.033,641.504,2777.1,33.7,181.6,4.42,3.8,199.311,3.58,0.84
|
||||
1967.0,4.0,3980.97,2465.7,462.834,640.234,2797.4,34.1,184.3,4.9,3.9,199.808,4.72,0.18
|
||||
1968.0,1.0,4063.013,2524.6,472.907,651.378,2846.2,34.4,186.6,5.18,3.7,200.208,3.5,1.67
|
||||
1968.0,2.0,4131.998,2563.3,492.026,646.145,2893.5,34.9,190.5,5.5,3.5,200.706,5.77,-0.28
|
||||
1968.0,3.0,4160.267,2611.5,476.053,640.615,2899.3,35.3,194.0,5.21,3.5,201.29,4.56,0.65
|
||||
1968.0,4.0,4178.293,2623.5,480.998,636.729,2918.4,35.7,198.7,5.85,3.4,201.76,4.51,1.34
|
||||
1969.0,1.0,4244.1,2652.9,512.686,633.224,2923.4,36.3,200.7,6.08,3.4,202.161,6.67,-0.58
|
||||
1969.0,2.0,4256.46,2669.8,508.601,623.16,2952.9,36.8,201.7,6.49,3.4,202.677,5.47,1.02
|
||||
1969.0,3.0,4283.378,2682.7,520.36,623.613,3012.9,37.3,202.9,7.02,3.6,203.302,5.4,1.63
|
||||
1969.0,4.0,4263.261,2704.1,492.334,606.9,3034.9,37.9,206.2,7.64,3.6,203.849,6.38,1.26
|
||||
1970.0,1.0,4256.573,2720.7,476.925,594.888,3050.1,38.5,206.7,6.76,4.2,204.401,6.28,0.47
|
||||
1970.0,2.0,4264.289,2733.2,478.419,576.257,3103.5,38.9,208.0,6.66,4.8,205.052,4.13,2.52
|
||||
1970.0,3.0,4302.259,2757.1,486.594,567.743,3145.4,39.4,212.9,6.15,5.2,205.788,5.11,1.04
|
||||
1970.0,4.0,4256.637,2749.6,458.406,564.666,3135.1,39.9,215.5,4.86,5.8,206.466,5.04,-0.18
|
||||
1971.0,1.0,4374.016,2802.2,517.935,542.709,3197.3,40.1,220.0,3.65,5.9,207.065,2.0,1.65
|
||||
1971.0,2.0,4398.829,2827.9,533.986,534.905,3245.3,40.6,224.9,4.76,5.9,207.661,4.96,-0.19
|
||||
1971.0,3.0,4433.943,2850.4,541.01,532.646,3259.7,40.9,227.2,4.7,6.0,208.345,2.94,1.75
|
||||
1971.0,4.0,4446.264,2897.8,524.085,516.14,3294.2,41.2,230.1,3.87,6.0,208.917,2.92,0.95
|
||||
1972.0,1.0,4525.769,2936.5,561.147,518.192,3314.9,41.5,235.6,3.55,5.8,209.386,2.9,0.64
|
||||
1972.0,2.0,4633.101,2992.6,595.495,526.473,3346.1,41.8,238.8,3.86,5.7,209.896,2.88,0.98
|
||||
1972.0,3.0,4677.503,3038.8,603.97,498.116,3414.6,42.2,245.0,4.47,5.6,210.479,3.81,0.66
|
||||
1972.0,4.0,4754.546,3110.1,607.104,496.54,3550.5,42.7,251.5,5.09,5.3,210.985,4.71,0.38
|
||||
1973.0,1.0,4876.166,3167.0,645.654,504.838,3590.7,43.7,252.7,5.98,5.0,211.42,9.26,-3.28
|
||||
1973.0,2.0,4932.571,3165.4,675.837,497.033,3626.2,44.2,257.5,7.19,4.9,211.909,4.55,2.64
|
||||
1973.0,3.0,4906.252,3176.7,649.412,475.897,3644.4,45.6,259.0,8.06,4.8,212.475,12.47,-4.41
|
||||
1973.0,4.0,4953.05,3167.4,674.253,476.174,3688.9,46.8,263.8,7.68,4.8,212.932,10.39,-2.71
|
||||
1974.0,1.0,4909.617,3139.7,631.23,491.043,3632.3,48.1,267.2,7.8,5.1,213.361,10.96,-3.16
|
||||
1974.0,2.0,4922.188,3150.6,628.102,490.177,3601.1,49.3,269.3,7.89,5.2,213.854,9.86,-1.96
|
||||
1974.0,3.0,4873.52,3163.6,592.672,492.586,3612.4,51.0,272.3,8.16,5.6,214.451,13.56,-5.4
|
||||
1974.0,4.0,4854.34,3117.3,598.306,496.176,3596.0,52.3,273.9,6.96,6.6,214.931,10.07,-3.11
|
||||
1975.0,1.0,4795.295,3143.4,493.212,490.603,3581.9,53.0,276.2,5.53,8.2,215.353,5.32,0.22
|
||||
1975.0,2.0,4831.942,3195.8,476.085,486.679,3749.3,54.0,283.7,5.57,8.9,215.973,7.48,-1.91
|
||||
1975.0,3.0,4913.328,3241.4,516.402,498.836,3698.6,54.9,285.4,6.27,8.5,216.587,6.61,-0.34
|
||||
1975.0,4.0,4977.511,3275.7,530.596,500.141,3736.0,55.8,288.4,5.26,8.3,217.095,6.5,-1.24
|
||||
1976.0,1.0,5090.663,3341.2,585.541,495.568,3791.0,56.1,294.7,4.91,7.7,217.528,2.14,2.77
|
||||
1976.0,2.0,5128.947,3371.8,610.513,494.532,3822.2,57.0,297.2,5.28,7.6,218.035,6.37,-1.09
|
||||
1976.0,3.0,5154.072,3407.5,611.646,493.141,3856.7,57.9,302.0,5.05,7.7,218.644,6.27,-1.22
|
||||
1976.0,4.0,5191.499,3451.8,615.898,494.415,3884.4,58.7,308.3,4.57,7.8,219.179,5.49,-0.92
|
||||
1977.0,1.0,5251.762,3491.3,646.198,498.509,3887.5,60.0,316.0,4.6,7.5,219.684,8.76,-4.16
|
||||
1977.0,2.0,5356.131,3510.6,696.141,506.695,3931.8,60.8,320.2,5.06,7.1,220.239,5.3,-0.24
|
||||
1977.0,3.0,5451.921,3544.1,734.078,509.605,3990.8,61.6,326.4,5.82,6.9,220.904,5.23,0.59
|
||||
1977.0,4.0,5450.793,3597.5,713.356,504.584,4071.2,62.7,334.4,6.2,6.6,221.477,7.08,-0.88
|
||||
1978.0,1.0,5469.405,3618.5,727.504,506.314,4096.4,63.9,339.9,6.34,6.3,221.991,7.58,-1.24
|
||||
1978.0,2.0,5684.569,3695.9,777.454,518.366,4143.4,65.5,347.6,6.72,6.0,222.585,9.89,-3.18
|
||||
1978.0,3.0,5740.3,3711.4,801.452,520.199,4177.1,67.1,353.3,7.64,6.0,223.271,9.65,-2.01
|
||||
1978.0,4.0,5816.222,3741.3,819.689,524.782,4209.8,68.5,358.6,9.02,5.9,223.865,8.26,0.76
|
||||
1979.0,1.0,5825.949,3760.2,819.556,525.524,4255.9,70.6,368.0,9.42,5.9,224.438,12.08,-2.66
|
||||
1979.0,2.0,5831.418,3758.0,817.66,532.04,4226.1,73.0,377.2,9.3,5.7,225.055,13.37,-4.07
|
||||
1979.0,3.0,5873.335,3794.9,801.742,531.232,4250.3,75.2,380.8,10.49,5.9,225.801,11.88,-1.38
|
||||
1979.0,4.0,5889.495,3805.0,786.817,531.126,4284.3,78.0,385.8,11.94,5.9,226.451,14.62,-2.68
|
||||
1980.0,1.0,5908.467,3798.4,781.114,548.115,4296.2,80.9,383.8,13.75,6.3,227.061,14.6,-0.85
|
||||
1980.0,2.0,5787.373,3712.2,710.64,561.895,4236.1,82.6,394.0,7.9,7.3,227.726,8.32,-0.42
|
||||
1980.0,3.0,5776.617,3752.0,656.477,554.292,4279.7,84.7,409.0,10.34,7.7,228.417,10.04,0.3
|
||||
1980.0,4.0,5883.46,3802.0,723.22,556.13,4368.1,87.2,411.3,14.75,7.4,228.937,11.64,3.11
|
||||
1981.0,1.0,6005.717,3822.8,795.091,567.618,4358.1,89.1,427.4,13.95,7.4,229.403,8.62,5.32
|
||||
1981.0,2.0,5957.795,3822.8,757.24,584.54,4358.6,91.5,426.9,15.33,7.4,229.966,10.63,4.69
|
||||
1981.0,3.0,6030.184,3838.3,804.242,583.89,4455.4,93.4,428.4,14.58,7.4,230.641,8.22,6.36
|
||||
1981.0,4.0,5955.062,3809.3,773.053,590.125,4464.4,94.4,442.7,11.33,8.2,231.157,4.26,7.07
|
||||
1982.0,1.0,5857.333,3833.9,692.514,591.043,4469.6,95.0,447.1,12.95,8.8,231.645,2.53,10.42
|
||||
1982.0,2.0,5889.074,3847.7,691.9,596.403,4500.8,97.5,448.0,11.97,9.4,232.188,10.39,1.58
|
||||
1982.0,3.0,5866.37,3877.2,683.825,605.37,4520.6,98.1,464.5,8.1,9.9,232.816,2.45,5.65
|
||||
1982.0,4.0,5871.001,3947.9,622.93,623.307,4536.4,97.9,477.2,7.96,10.7,233.322,-0.82,8.77
|
||||
1983.0,1.0,5944.02,3986.6,645.11,630.873,4572.2,98.8,493.2,8.22,10.4,233.781,3.66,4.56
|
||||
1983.0,2.0,6077.619,4065.7,707.372,644.322,4605.5,99.8,507.8,8.69,10.1,234.307,4.03,4.66
|
||||
1983.0,3.0,6197.468,4137.6,754.937,662.412,4674.7,100.8,517.2,8.99,9.4,234.907,3.99,5.01
|
||||
1983.0,4.0,6325.574,4203.2,834.427,639.197,4771.1,102.1,525.1,8.89,8.5,235.385,5.13,3.76
|
||||
1984.0,1.0,6448.264,4239.2,921.763,644.635,4875.4,103.3,535.0,9.43,7.9,235.839,4.67,4.76
|
||||
1984.0,2.0,6559.594,4299.9,952.841,664.839,4959.4,104.1,540.9,9.94,7.5,236.348,3.09,6.85
|
||||
1984.0,3.0,6623.343,4333.0,974.989,662.294,5036.6,105.1,543.7,10.19,7.4,236.976,3.82,6.37
|
||||
1984.0,4.0,6677.264,4390.1,958.993,684.282,5084.5,105.7,557.0,8.14,7.3,237.468,2.28,5.87
|
||||
1985.0,1.0,6740.275,4464.6,927.375,691.613,5072.0,107.0,570.4,8.25,7.3,237.9,4.89,3.36
|
||||
1985.0,2.0,6797.344,4505.2,943.383,708.524,5172.7,107.7,589.1,7.17,7.3,238.466,2.61,4.56
|
||||
1985.0,3.0,6903.523,4590.8,932.959,732.305,5140.7,108.5,607.8,7.13,7.2,239.113,2.96,4.17
|
||||
1985.0,4.0,6955.918,4600.9,969.434,732.026,5193.9,109.9,621.4,7.14,7.0,239.638,5.13,2.01
|
||||
1986.0,1.0,7022.757,4639.3,967.442,728.125,5255.8,108.7,641.0,6.56,7.0,240.094,-4.39,10.95
|
||||
1986.0,2.0,7050.969,4688.7,945.972,751.334,5315.5,109.5,670.3,6.06,7.2,240.651,2.93,3.13
|
||||
1986.0,3.0,7118.95,4770.7,916.315,779.77,5343.3,110.2,694.9,5.31,7.0,241.274,2.55,2.76
|
||||
1986.0,4.0,7153.359,4799.4,917.736,767.671,5346.5,111.4,730.2,5.44,6.8,241.784,4.33,1.1
|
||||
1987.0,1.0,7193.019,4792.1,945.776,772.247,5379.4,112.7,743.9,5.61,6.6,242.252,4.64,0.97
|
||||
1987.0,2.0,7269.51,4856.3,947.1,782.962,5321.0,113.8,743.0,5.67,6.3,242.804,3.89,1.79
|
||||
1987.0,3.0,7332.558,4910.4,948.055,783.804,5416.2,115.0,756.2,6.19,6.0,243.446,4.2,1.99
|
||||
1987.0,4.0,7458.022,4922.2,1021.98,795.467,5493.1,116.0,756.2,5.76,5.9,243.981,3.46,2.29
|
||||
1988.0,1.0,7496.6,5004.4,964.398,773.851,5562.1,117.2,768.1,5.76,5.7,244.445,4.12,1.64
|
||||
1988.0,2.0,7592.881,5040.8,987.858,765.98,5614.3,118.5,781.4,6.48,5.5,245.021,4.41,2.07
|
||||
1988.0,3.0,7632.082,5080.6,994.204,760.245,5657.5,119.9,783.3,7.22,5.5,245.693,4.7,2.52
|
||||
1988.0,4.0,7733.991,5140.4,1007.371,783.065,5708.5,121.2,785.7,8.03,5.3,246.224,4.31,3.72
|
||||
1989.0,1.0,7806.603,5159.3,1045.975,767.024,5773.4,123.1,779.2,8.67,5.2,246.721,6.22,2.44
|
||||
1989.0,2.0,7865.016,5182.4,1033.753,784.275,5749.8,124.5,777.8,8.15,5.2,247.342,4.52,3.63
|
||||
1989.0,3.0,7927.393,5236.1,1021.604,791.819,5787.0,125.4,786.6,7.76,5.3,248.067,2.88,4.88
|
||||
1989.0,4.0,7944.697,5261.7,1011.119,787.844,5831.3,127.5,795.4,7.65,5.4,248.659,6.64,1.01
|
||||
1990.0,1.0,8027.693,5303.3,1021.07,799.681,5875.1,128.9,806.2,7.8,5.3,249.306,4.37,3.44
|
||||
1990.0,2.0,8059.598,5320.8,1021.36,800.639,5913.9,130.5,810.1,7.7,5.3,250.132,4.93,2.76
|
||||
1990.0,3.0,8059.476,5341.0,997.319,793.513,5918.1,133.4,819.8,7.33,5.7,251.057,8.79,-1.46
|
||||
1990.0,4.0,7988.864,5299.5,934.248,800.525,5878.2,134.7,827.2,6.67,6.1,251.889,3.88,2.79
|
||||
1991.0,1.0,7950.164,5284.4,896.21,806.775,5896.3,135.1,843.2,5.83,6.6,252.643,1.19,4.65
|
||||
1991.0,2.0,8003.822,5324.7,891.704,809.081,5941.1,136.2,861.5,5.54,6.8,253.493,3.24,2.29
|
||||
1991.0,3.0,8037.538,5345.0,913.904,793.987,5953.6,137.2,878.0,5.18,6.9,254.435,2.93,2.25
|
||||
1991.0,4.0,8069.046,5342.6,948.891,778.378,5992.4,138.3,910.4,4.14,7.1,255.214,3.19,0.95
|
||||
1992.0,1.0,8157.616,5434.5,927.796,778.568,6082.9,139.4,943.8,3.88,7.4,255.992,3.17,0.71
|
||||
1992.0,2.0,8244.294,5466.7,988.912,777.762,6129.5,140.5,963.2,3.5,7.6,256.894,3.14,0.36
|
||||
1992.0,3.0,8329.361,5527.1,999.135,786.639,6160.6,141.7,1003.8,2.97,7.6,257.861,3.4,-0.44
|
||||
1992.0,4.0,8417.016,5594.6,1030.758,787.064,6248.2,142.8,1030.4,3.12,7.4,258.679,3.09,0.02
|
||||
1993.0,1.0,8432.485,5617.2,1054.979,762.901,6156.5,143.8,1047.6,2.92,7.2,259.414,2.79,0.13
|
||||
1993.0,2.0,8486.435,5671.1,1063.263,752.158,6252.3,144.5,1084.5,3.02,7.1,260.255,1.94,1.08
|
||||
1993.0,3.0,8531.108,5732.7,1062.514,744.227,6265.7,145.6,1113.0,3.0,6.8,261.163,3.03,-0.04
|
||||
1993.0,4.0,8643.769,5783.7,1118.583,748.102,6358.1,146.3,1131.6,3.05,6.6,261.919,1.92,1.13
|
||||
1994.0,1.0,8727.919,5848.1,1166.845,721.288,6332.6,147.2,1141.1,3.48,6.6,262.631,2.45,1.02
|
||||
1994.0,2.0,8847.303,5891.5,1234.855,717.197,6440.6,148.4,1150.5,4.2,6.2,263.436,3.25,0.96
|
||||
1994.0,3.0,8904.289,5938.7,1212.655,736.89,6487.9,149.4,1150.1,4.68,6.0,264.301,2.69,2.0
|
||||
1994.0,4.0,9003.18,5997.3,1269.19,716.702,6574.0,150.5,1151.4,5.53,5.6,265.044,2.93,2.6
|
||||
1995.0,1.0,9025.267,6004.3,1282.09,715.326,6616.6,151.8,1149.3,5.72,5.5,265.755,3.44,2.28
|
||||
1995.0,2.0,9044.668,6053.5,1247.61,712.492,6617.2,152.6,1145.4,5.52,5.7,266.557,2.1,3.42
|
||||
1995.0,3.0,9120.684,6107.6,1235.601,707.649,6666.8,153.5,1137.3,5.32,5.7,267.456,2.35,2.97
|
||||
1995.0,4.0,9184.275,6150.6,1270.392,681.081,6706.2,154.7,1123.5,5.17,5.6,268.151,3.11,2.05
|
||||
1996.0,1.0,9247.188,6206.9,1287.128,695.265,6777.7,156.1,1124.8,4.91,5.5,268.853,3.6,1.31
|
||||
1996.0,2.0,9407.052,6277.1,1353.795,705.172,6850.6,157.0,1112.4,5.09,5.5,269.667,2.3,2.79
|
||||
1996.0,3.0,9488.879,6314.6,1422.059,692.741,6908.9,158.2,1086.1,5.04,5.3,270.581,3.05,2.0
|
||||
1996.0,4.0,9592.458,6366.1,1418.193,690.744,6946.8,159.4,1081.5,4.99,5.3,271.36,3.02,1.97
|
||||
1997.0,1.0,9666.235,6430.2,1451.304,681.445,7008.9,159.9,1063.8,5.1,5.2,272.083,1.25,3.85
|
||||
1997.0,2.0,9809.551,6456.2,1543.976,693.525,7061.5,160.4,1066.2,5.01,5.0,272.912,1.25,3.76
|
||||
1997.0,3.0,9932.672,6566.0,1571.426,691.261,7142.4,161.5,1065.5,5.02,4.9,273.852,2.73,2.29
|
||||
1997.0,4.0,10008.874,6641.1,1596.523,690.311,7241.5,162.0,1074.4,5.11,4.7,274.626,1.24,3.88
|
||||
1998.0,1.0,10103.425,6707.2,1672.732,668.783,7406.2,162.2,1076.1,5.02,4.6,275.304,0.49,4.53
|
||||
1998.0,2.0,10194.277,6822.6,1652.716,687.184,7512.0,163.2,1075.0,4.98,4.4,276.115,2.46,2.52
|
||||
1998.0,3.0,10328.787,6913.1,1700.071,681.472,7591.0,163.9,1086.0,4.49,4.5,277.003,1.71,2.78
|
||||
1998.0,4.0,10507.575,7019.1,1754.743,688.147,7646.5,164.7,1097.8,4.38,4.4,277.79,1.95,2.43
|
||||
1999.0,1.0,10601.179,7088.3,1809.993,683.601,7698.4,165.9,1101.9,4.39,4.3,278.451,2.9,1.49
|
||||
1999.0,2.0,10684.049,7199.9,1803.674,683.594,7716.0,166.7,1098.7,4.54,4.3,279.295,1.92,2.62
|
||||
1999.0,3.0,10819.914,7286.4,1848.949,697.936,7765.9,168.1,1102.3,4.75,4.2,280.203,3.35,1.41
|
||||
1999.0,4.0,11014.254,7389.2,1914.567,713.445,7887.7,169.3,1121.9,5.2,4.1,280.976,2.85,2.35
|
||||
2000.0,1.0,11043.044,7501.3,1887.836,685.216,8053.4,170.9,1113.5,5.63,4.0,281.653,3.76,1.87
|
||||
2000.0,2.0,11258.454,7571.8,2018.529,712.641,8135.9,172.7,1103.0,5.81,3.9,282.385,4.19,1.62
|
||||
2000.0,3.0,11267.867,7645.9,1986.956,698.827,8222.3,173.9,1098.7,6.07,4.0,283.19,2.77,3.3
|
||||
2000.0,4.0,11334.544,7713.5,1987.845,695.597,8234.6,175.6,1097.7,5.7,3.9,283.9,3.89,1.81
|
||||
2001.0,1.0,11297.171,7744.3,1882.691,710.403,8296.5,176.4,1114.9,4.39,4.2,284.55,1.82,2.57
|
||||
2001.0,2.0,11371.251,7773.5,1876.65,725.623,8273.7,177.4,1139.7,3.54,4.4,285.267,2.26,1.28
|
||||
2001.0,3.0,11340.075,7807.7,1837.074,730.493,8484.5,177.6,1166.0,2.72,4.8,286.047,0.45,2.27
|
||||
2001.0,4.0,11380.128,7930.0,1731.189,739.318,8385.5,177.7,1190.9,1.74,5.5,286.728,0.23,1.51
|
||||
2002.0,1.0,11477.868,7957.3,1789.327,756.915,8611.6,179.3,1185.9,1.75,5.7,287.328,3.59,-1.84
|
||||
2002.0,2.0,11538.77,7997.8,1810.779,774.408,8658.9,180.0,1199.5,1.7,5.8,288.028,1.56,0.14
|
||||
2002.0,3.0,11596.43,8052.0,1814.531,786.673,8629.2,181.2,1204.0,1.61,5.7,288.783,2.66,-1.05
|
||||
2002.0,4.0,11598.824,8080.6,1813.219,799.967,8649.6,182.6,1226.8,1.2,5.8,289.421,3.08,-1.88
|
||||
2003.0,1.0,11645.819,8122.3,1813.141,800.196,8681.3,183.2,1248.4,1.14,5.9,290.019,1.31,-0.17
|
||||
2003.0,2.0,11738.706,8197.8,1823.698,838.775,8812.5,183.7,1287.9,0.96,6.2,290.704,1.09,-0.13
|
||||
2003.0,3.0,11935.461,8312.1,1889.883,839.598,8935.4,184.9,1297.3,0.94,6.1,291.449,2.6,-1.67
|
||||
2003.0,4.0,12042.817,8358.0,1959.783,845.722,8986.4,186.3,1306.1,0.9,5.8,292.057,3.02,-2.11
|
||||
2004.0,1.0,12127.623,8437.6,1970.015,856.57,9025.9,187.4,1332.1,0.94,5.7,292.635,2.35,-1.42
|
||||
2004.0,2.0,12213.818,8483.2,2055.58,861.44,9115.0,189.1,1340.5,1.21,5.6,293.31,3.61,-2.41
|
||||
2004.0,3.0,12303.533,8555.8,2082.231,876.385,9175.9,190.8,1361.0,1.63,5.4,294.066,3.58,-1.95
|
||||
2004.0,4.0,12410.282,8654.2,2125.152,865.596,9303.4,191.8,1366.6,2.2,5.4,294.741,2.09,0.11
|
||||
2005.0,1.0,12534.113,8719.0,2170.299,869.204,9189.6,193.8,1357.8,2.69,5.3,295.308,4.15,-1.46
|
||||
2005.0,2.0,12587.535,8802.9,2131.468,870.044,9253.0,194.7,1366.6,3.01,5.1,295.994,1.85,1.16
|
||||
2005.0,3.0,12683.153,8865.6,2154.949,890.394,9308.0,199.2,1375.0,3.52,5.0,296.77,9.14,-5.62
|
||||
2005.0,4.0,12748.699,8888.5,2232.193,875.557,9358.7,199.4,1380.6,4.0,4.9,297.435,0.4,3.6
|
||||
2006.0,1.0,12915.938,8986.6,2264.721,900.511,9533.8,200.7,1380.5,4.51,4.7,298.061,2.6,1.91
|
||||
2006.0,2.0,12962.462,9035.0,2261.247,892.839,9617.3,202.7,1369.2,4.82,4.7,298.766,3.97,0.85
|
||||
2006.0,3.0,12965.916,9090.7,2229.636,892.002,9662.5,201.9,1369.4,4.9,4.7,299.593,-1.58,6.48
|
||||
2006.0,4.0,13060.679,9181.6,2165.966,894.404,9788.8,203.574,1373.6,4.92,4.4,300.32,3.3,1.62
|
||||
2007.0,1.0,13099.901,9265.1,2132.609,882.766,9830.2,205.92,1379.7,4.95,4.5,300.977,4.58,0.36
|
||||
2007.0,2.0,13203.977,9291.5,2162.214,898.713,9842.7,207.338,1370.0,4.72,4.5,301.714,2.75,1.97
|
||||
2007.0,3.0,13321.109,9335.6,2166.491,918.983,9883.9,209.133,1379.2,4.0,4.7,302.509,3.45,0.55
|
||||
2007.0,4.0,13391.249,9363.6,2123.426,925.11,9886.2,212.495,1377.4,3.01,4.8,303.204,6.38,-3.37
|
||||
2008.0,1.0,13366.865,9349.6,2082.886,943.372,9826.8,213.997,1384.0,1.56,4.9,303.803,2.82,-1.26
|
||||
2008.0,2.0,13415.266,9351.0,2026.518,961.28,10059.0,218.61,1409.3,1.74,5.4,304.483,8.53,-6.79
|
||||
2008.0,3.0,13324.6,9267.7,1990.693,991.551,9838.3,216.889,1474.7,1.17,6.0,305.27,-3.16,4.33
|
||||
2008.0,4.0,13141.92,9195.3,1857.661,1007.273,9920.4,212.174,1576.5,0.12,6.9,305.952,-8.79,8.91
|
||||
2009.0,1.0,12925.41,9209.2,1558.494,996.287,9926.4,212.671,1592.8,0.22,8.1,306.547,0.94,-0.71
|
||||
2009.0,2.0,12901.504,9189.0,1456.678,1023.528,10077.5,214.469,1653.6,0.18,9.2,307.226,3.37,-3.19
|
||||
2009.0,3.0,12990.341,9256.0,1486.398,1044.088,10040.6,216.385,1673.9,0.12,9.6,308.013,3.56,-3.44
|
|
|
@ -1,193 +0,0 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 17,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from IPython.core.interactiveshell import InteractiveShell #执行该代码可以使得当前nb支持多输出\n",
|
||||
"InteractiveShell.ast_node_interactivity = \"all\" \n",
|
||||
"import numpy as np \n",
|
||||
"import pandas as pd \n",
|
||||
"import re"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**作业**"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 62,
|
||||
"metadata": {
|
||||
"scrolled": true
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"<class 'dict_values'>\n",
|
||||
"《唐诗三百首》总共有 313 首诗,其中 李白 有 29 首诗,占比为 0.0926517571884984 排名第 2\n",
|
||||
"[[1, 2, 7, [3, 4, 5, 6]], [17, 22, 28, [23, 24, 25, 26, 27]], [1692, 3054, 3059, [3055, 3056, 3057, 3058]]]\n",
|
||||
"双字词中,词频大于1次的包括: [('苍苍', 2), ('幽径', 2), ('美酒', 2), ('举杯', 2), ('明月', 4), ('行乐', 2), ('断肠', 3), ('春风', 4), ('长风', 3), ('万里', 5), ('不见', 5), ('高楼', 2), ('长安', 3), ('秋风', 2), ('门前', 2), ('低头', 2), ('不可', 4), ('猿声', 2), ('天上', 2), ('一生', 2), ('不能', 2), ('红颜', 2), ('黄鹤', 3), ('五岳', 2), ('名山', 2), ('庐山', 3), ('倒挂', 2), ('不到', 2), ('天长', 2), ('我心', 2), ('彩云', 2), ('天姥', 2), ('四万', 2), ('对此', 2), ('迷花', 2), ('日月', 2), ('纷纷', 2), ('如麻', 2), ('古来', 2), ('流水', 3), ('何时', 2), ('不得', 2), ('请君', 2), ('可以', 2), ('青天', 7), ('人生', 2), ('明朝', 2), ('蜀道', 3), ('之难', 3), ('难于', 3), ('上青', 3), ('茫然', 2), ('峨嵋', 2), ('下有', 2), ('长叹', 2), ('相思', 2), ('凤凰', 3), ('明镜', 2), ('十千', 2), ('黄河', 2), ('行路', 2), ('千金', 2), ('夫子', 2), ('故乡', 2), ('浮云', 2), ('挥手', 2), ('秋月', 2)]\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ename": "OSError",
|
||||
"evalue": "cannot open resource",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
|
||||
"\u001B[0;31mOSError\u001B[0m Traceback (most recent call last)",
|
||||
"Input \u001B[0;32mIn [62]\u001B[0m, in \u001B[0;36m<cell line: 80>\u001B[0;34m()\u001B[0m\n\u001B[1;32m 77\u001B[0m \u001B[38;5;28mprint\u001B[39m( \u001B[38;5;124m'\u001B[39m\u001B[38;5;124m双字词中,词频大于1次的包括:\u001B[39m\u001B[38;5;124m'\u001B[39m,doubleword(jb))\n\u001B[1;32m 79\u001B[0m w \u001B[38;5;241m=\u001B[39m WordCloud(font_path\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mC:\u001B[39m\u001B[38;5;130;01m\\\\\u001B[39;00m\u001B[38;5;124mWindows\u001B[39m\u001B[38;5;130;01m\\\\\u001B[39;00m\u001B[38;5;124mFonts\u001B[39m\u001B[38;5;130;01m\\\\\u001B[39;00m\u001B[38;5;124mSTFANGSO.ttf\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m---> 80\u001B[0m my_wordcloud\u001B[38;5;241m=\u001B[39m\u001B[43mw\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mgenerate\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[38;5;124;43m \u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mjoin\u001B[49m\u001B[43m(\u001B[49m\u001B[43mjb\u001B[49m\u001B[43m)\u001B[49m\u001B[43m)\u001B[49m \u001B[38;5;66;03m#生成词云\u001B[39;00m\n\u001B[1;32m 81\u001B[0m plt\u001B[38;5;241m.\u001B[39mimshow(my_wordcloud)\n\u001B[1;32m 82\u001B[0m plt\u001B[38;5;241m.\u001B[39maxis(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124moff\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n",
|
||||
"File \u001B[0;32m~/Library/Python/3.10/lib/python/site-packages/wordcloud/wordcloud.py:639\u001B[0m, in \u001B[0;36mWordCloud.generate\u001B[0;34m(self, text)\u001B[0m\n\u001B[1;32m 624\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mgenerate\u001B[39m(\u001B[38;5;28mself\u001B[39m, text):\n\u001B[1;32m 625\u001B[0m \u001B[38;5;124;03m\"\"\"Generate wordcloud from text.\u001B[39;00m\n\u001B[1;32m 626\u001B[0m \n\u001B[1;32m 627\u001B[0m \u001B[38;5;124;03m The input \"text\" is expected to be a natural text. If you pass a sorted\u001B[39;00m\n\u001B[0;32m (...)\u001B[0m\n\u001B[1;32m 637\u001B[0m \u001B[38;5;124;03m self\u001B[39;00m\n\u001B[1;32m 638\u001B[0m \u001B[38;5;124;03m \"\"\"\u001B[39;00m\n\u001B[0;32m--> 639\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mgenerate_from_text\u001B[49m\u001B[43m(\u001B[49m\u001B[43mtext\u001B[49m\u001B[43m)\u001B[49m\n",
|
||||
"File \u001B[0;32m~/Library/Python/3.10/lib/python/site-packages/wordcloud/wordcloud.py:621\u001B[0m, in \u001B[0;36mWordCloud.generate_from_text\u001B[0;34m(self, text)\u001B[0m\n\u001B[1;32m 604\u001B[0m \u001B[38;5;124;03m\"\"\"Generate wordcloud from text.\u001B[39;00m\n\u001B[1;32m 605\u001B[0m \n\u001B[1;32m 606\u001B[0m \u001B[38;5;124;03mThe input \"text\" is expected to be a natural text. If you pass a sorted\u001B[39;00m\n\u001B[0;32m (...)\u001B[0m\n\u001B[1;32m 618\u001B[0m \u001B[38;5;124;03mself\u001B[39;00m\n\u001B[1;32m 619\u001B[0m \u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[1;32m 620\u001B[0m words \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mprocess_text(text)\n\u001B[0;32m--> 621\u001B[0m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mgenerate_from_frequencies\u001B[49m\u001B[43m(\u001B[49m\u001B[43mwords\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 622\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m\n",
|
||||
"File \u001B[0;32m~/Library/Python/3.10/lib/python/site-packages/wordcloud/wordcloud.py:453\u001B[0m, in \u001B[0;36mWordCloud.generate_from_frequencies\u001B[0;34m(self, frequencies, max_font_size)\u001B[0m\n\u001B[1;32m 451\u001B[0m font_size \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mheight\n\u001B[1;32m 452\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[0;32m--> 453\u001B[0m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mgenerate_from_frequencies\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;28;43mdict\u001B[39;49m\u001B[43m(\u001B[49m\u001B[43mfrequencies\u001B[49m\u001B[43m[\u001B[49m\u001B[43m:\u001B[49m\u001B[38;5;241;43m2\u001B[39;49m\u001B[43m]\u001B[49m\u001B[43m)\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 454\u001B[0m \u001B[43m \u001B[49m\u001B[43mmax_font_size\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mheight\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 455\u001B[0m \u001B[38;5;66;03m# find font sizes\u001B[39;00m\n\u001B[1;32m 456\u001B[0m sizes \u001B[38;5;241m=\u001B[39m [x[\u001B[38;5;241m1\u001B[39m] \u001B[38;5;28;01mfor\u001B[39;00m x \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mlayout_]\n",
|
||||
"File \u001B[0;32m~/Library/Python/3.10/lib/python/site-packages/wordcloud/wordcloud.py:503\u001B[0m, in \u001B[0;36mWordCloud.generate_from_frequencies\u001B[0;34m(self, frequencies, max_font_size)\u001B[0m\n\u001B[1;32m 500\u001B[0m tried_other_orientation \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;01mFalse\u001B[39;00m\n\u001B[1;32m 501\u001B[0m \u001B[38;5;28;01mwhile\u001B[39;00m \u001B[38;5;28;01mTrue\u001B[39;00m:\n\u001B[1;32m 502\u001B[0m \u001B[38;5;66;03m# try to find a position\u001B[39;00m\n\u001B[0;32m--> 503\u001B[0m font \u001B[38;5;241m=\u001B[39m \u001B[43mImageFont\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mtruetype\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mfont_path\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mfont_size\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 504\u001B[0m \u001B[38;5;66;03m# transpose font optionally\u001B[39;00m\n\u001B[1;32m 505\u001B[0m transposed_font \u001B[38;5;241m=\u001B[39m ImageFont\u001B[38;5;241m.\u001B[39mTransposedFont(\n\u001B[1;32m 506\u001B[0m font, orientation\u001B[38;5;241m=\u001B[39morientation)\n",
|
||||
"File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/PIL/ImageFont.py:844\u001B[0m, in \u001B[0;36mtruetype\u001B[0;34m(font, size, index, encoding, layout_engine)\u001B[0m\n\u001B[1;32m 841\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m FreeTypeFont(font, size, index, encoding, layout_engine)\n\u001B[1;32m 843\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[0;32m--> 844\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[43mfreetype\u001B[49m\u001B[43m(\u001B[49m\u001B[43mfont\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 845\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mOSError\u001B[39;00m:\n\u001B[1;32m 846\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m isPath(font):\n",
|
||||
"File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/PIL/ImageFont.py:841\u001B[0m, in \u001B[0;36mtruetype.<locals>.freetype\u001B[0;34m(font)\u001B[0m\n\u001B[1;32m 840\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mfreetype\u001B[39m(font):\n\u001B[0;32m--> 841\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[43mFreeTypeFont\u001B[49m\u001B[43m(\u001B[49m\u001B[43mfont\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43msize\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mindex\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mencoding\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mlayout_engine\u001B[49m\u001B[43m)\u001B[49m\n",
|
||||
"File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/PIL/ImageFont.py:193\u001B[0m, in \u001B[0;36mFreeTypeFont.__init__\u001B[0;34m(self, font, size, index, encoding, layout_engine)\u001B[0m\n\u001B[1;32m 191\u001B[0m load_from_bytes(f)\n\u001B[1;32m 192\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m\n\u001B[0;32m--> 193\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mfont \u001B[38;5;241m=\u001B[39m \u001B[43mcore\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mgetfont\u001B[49m\u001B[43m(\u001B[49m\n\u001B[1;32m 194\u001B[0m \u001B[43m \u001B[49m\u001B[43mfont\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43msize\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mindex\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mencoding\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mlayout_engine\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mlayout_engine\u001B[49m\n\u001B[1;32m 195\u001B[0m \u001B[43m \u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 196\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m 197\u001B[0m load_from_bytes(font)\n",
|
||||
"\u001B[0;31mOSError\u001B[0m: cannot open resource"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import re\n",
|
||||
"import jieba\n",
|
||||
"from collections import defaultdict\n",
|
||||
"from collections import Counter\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"from wordcloud import WordCloud\n",
|
||||
"\"\"\"\n",
|
||||
"这段代码实现了对《唐诗三百首》中某位作者的诗词进行分析,并生成了该作者诗词中出现频率大于1的双字词的词云。\n",
|
||||
"代码中的data_pre函数将原始数据按照作者、标题、注解等信息进行分类整理,并返回一个字典,其中包含每个作者的诗词行号、每首诗的标题行号、每首诗的注解行号等信息。\n",
|
||||
"doubleword函数用于遍历词列表并找到所有双字词,并将频次写入字典,再从字典中找出符合要求的词。\n",
|
||||
"poem函数用于将每个作者的诗词行号转换为诗词内容,并将所有诗词拼接成一个字符串列表。\n",
|
||||
"最后,使用了jieba分词库对诗词进行分词,并使用WordCloud库生成词云图。\n",
|
||||
"\"\"\"\n",
|
||||
"\n",
|
||||
"def data_pre(data):\n",
|
||||
" authorAll = {}\n",
|
||||
" titleAll = {}\n",
|
||||
" noteAll = {}\n",
|
||||
" lineNum = 0 # 循环读取行号\n",
|
||||
" for line in data:\n",
|
||||
" if(line != \"\\n\"):\n",
|
||||
" if('作者:' in line):\n",
|
||||
" # 利用正则查找冒号后的字\n",
|
||||
" author = re.search(r'作者:(.+)', line).group(1)\n",
|
||||
" authorAll[lineNum] = author\n",
|
||||
" elif '《' in line and '》' in line:\n",
|
||||
" # 用正则查找书名号中的字\n",
|
||||
" title = re.search(r'《(.+)》', line).group(1)\n",
|
||||
" titleAll[lineNum] = title\n",
|
||||
" elif '【注解】:' in line:\n",
|
||||
" # 用正则找注解后的几行\n",
|
||||
" note = re.findall(r'【注解】:\\n(.+?)\\n', line, re.DOTALL)\n",
|
||||
" noteAll[lineNum] = note\n",
|
||||
" lineNum += 1\n",
|
||||
" print(type(authorAll.values()))\n",
|
||||
" return authorAll, titleAll, noteAll\n",
|
||||
"\n",
|
||||
"def doubleword (words_lst):\n",
|
||||
" \"\"\"\n",
|
||||
" 遍历列表以找到所有双词,并将频次写入字典,再从字典中找出符合要求的词\n",
|
||||
" \"\"\"\n",
|
||||
" result_lst = []\n",
|
||||
" doublewords = {}\n",
|
||||
" for word in words_lst:\n",
|
||||
" # 用len过滤掉非双词\n",
|
||||
" if len(word) == 2:\n",
|
||||
" if word in doublewords:\n",
|
||||
" doublewords[word] += 1\n",
|
||||
" else:\n",
|
||||
" doublewords[word] = 1\n",
|
||||
" # 遍历所有词与频次\n",
|
||||
" for word, freq in doublewords.items():\n",
|
||||
" if freq > 1:\n",
|
||||
" # 用元组打包一对值\n",
|
||||
" result_lst.append((word, freq))\n",
|
||||
" return result_lst\n",
|
||||
"\n",
|
||||
"def poem (tanc_author, data):\n",
|
||||
" poems_lst = []\n",
|
||||
" for poems in tanc_author:\n",
|
||||
" content = ''\n",
|
||||
" # 取每一行拼成全部,也可使用切片操作\n",
|
||||
" lines = poems[-1]\n",
|
||||
" for line in lines:\n",
|
||||
" content += data[line]\n",
|
||||
" poems_lst.append(content.replace('\\n', ''))\n",
|
||||
" # 加入列表并去除换行标记\n",
|
||||
" return poems_lst\n",
|
||||
"\n",
|
||||
"data = open('唐诗三百首完整版.txt','rt',encoding = 'utf-8').readlines()\n",
|
||||
"authorAll,titleAll,noteAll = data_pre(data) #所有作者的行号、所有题目的行号、所有注解的行号\n",
|
||||
"\n",
|
||||
"# author = input(\"输入作者名:\")\n",
|
||||
"author='李白'\n",
|
||||
"authorDict = Counter(authorAll.values())\n",
|
||||
"authorNum= authorDict[author]\n",
|
||||
"allNum =len(authorAll) #sum(authorDict.values())\n",
|
||||
"print('《唐诗三百首》总共有',allNum,'首诗,其中', author ,'有',authorNum,'首诗,占比为',authorNum/allNum,'排名第',sorted(authorDict.values(),reverse=True).index(authorNum)+1) #李白数量\n",
|
||||
"\n",
|
||||
"#求tanc结构 ,即title、author、note、content\n",
|
||||
"tanc = defaultdict(list)\n",
|
||||
"for key, t,a,n in zip(authorAll.values(),titleAll.keys(),authorAll.keys(),noteAll.keys()): #每个作者的字典值包括标题、作者、注解、诗句所在的行数\n",
|
||||
" tanc[key].append([t,a,n,list(range(a+1,n))])\n",
|
||||
"print(tanc['张九龄']) #用于测试结构\n",
|
||||
"\n",
|
||||
"data_lst=poem(tanc[author], data) #返回该作者全部诗句列表\n",
|
||||
"#print(data_lst) #用于测试获得改作者全部诗词\n",
|
||||
"jb=jieba.lcut_for_search(''.join(data_lst)) #生成jieba分词\n",
|
||||
"print( '双字词中,词频大于1次的包括:',doubleword(jb))\n",
|
||||
"\n",
|
||||
"w = WordCloud(font_path=\"C:\\\\Windows\\\\Fonts\\\\STFANGSO.ttf\")\n",
|
||||
"my_wordcloud=w.generate(' '.join(jb)) #生成词云\n",
|
||||
"plt.imshow(my_wordcloud)\n",
|
||||
"plt.axis(\"off\")\n",
|
||||
"plt.show()"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"hide_input": false,
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.5"
|
||||
},
|
||||
"toc": {
|
||||
"base_numbering": 1,
|
||||
"nav_menu": {},
|
||||
"number_sections": true,
|
||||
"sideBar": true,
|
||||
"skip_h1_title": false,
|
||||
"title_cell": "Table of Contents",
|
||||
"title_sidebar": "Contents",
|
||||
"toc_cell": false,
|
||||
"toc_position": {},
|
||||
"toc_section_display": true,
|
||||
"toc_window_display": false
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
|
@ -1,394 +0,0 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"start_time": "2023-05-04T14:47:14.249433Z",
|
||||
"end_time": "2023-05-04T14:47:14.815684Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"\n",
|
||||
"from IPython.core.interactiveshell import InteractiveShell #执行该代码可以使得当前nb支持多输出\n",
|
||||
"InteractiveShell.ast_node_interactivity = \"all\" \n",
|
||||
"import numpy as np\n",
|
||||
"import pandas as pd \n",
|
||||
"pd.options.display.max_rows = 8 "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**作业**\n",
|
||||
"综合运用stack/unstack,pivot/melt"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"scrolled": true,
|
||||
"ExecuteTime": {
|
||||
"start_time": "2023-05-04T14:47:14.807387Z",
|
||||
"end_time": "2023-05-04T14:47:14.828436Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"item realgdp infl unemp\n",
|
||||
"date \n",
|
||||
"1959-03-31 2710.349 0.00 5.8\n",
|
||||
"1959-06-30 2778.801 2.34 5.1\n",
|
||||
"1959-09-30 2775.488 2.74 5.3\n",
|
||||
"1959-12-31 2785.204 0.27 5.6\n",
|
||||
"... ... ... ...\n",
|
||||
"2008-12-31 13141.920 -8.79 6.9\n",
|
||||
"2009-03-31 12925.410 0.94 8.1\n",
|
||||
"2009-06-30 12901.504 3.37 9.2\n",
|
||||
"2009-09-30 12990.341 3.56 9.6\n",
|
||||
"\n",
|
||||
"[203 rows x 3 columns]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"#有可能是版本问题,需要加入.strftime('%Y-%m-%d')\n",
|
||||
"data = pd.read_csv('../examples/macrodata.csv')\n",
|
||||
"data.index = pd.PeriodIndex(year=data.year, quarter=data.quarter,name='date').to_timestamp('D', 'end').strftime('%Y-%m-%d')\n",
|
||||
"data = data.reindex(columns=pd.Index(['realgdp', 'infl', 'unemp'], name='item'))\n",
|
||||
"print(data)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**作业1:**\n",
|
||||
"data通过stack/melt获得ldata"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"scrolled": true,
|
||||
"ExecuteTime": {
|
||||
"start_time": "2023-05-04T14:47:17.592602Z",
|
||||
"end_time": "2023-05-04T14:47:17.608357Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": " date item value\n0 1959-03-31 realgdp 2710.349\n1 1959-03-31 infl 0.000\n2 1959-03-31 unemp 5.800\n3 1959-06-30 realgdp 2778.801\n4 1959-06-30 infl 2.340",
|
||||
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>date</th>\n <th>item</th>\n <th>value</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1959-03-31</td>\n <td>realgdp</td>\n <td>2710.349</td>\n </tr>\n <tr>\n <th>1</th>\n <td>1959-03-31</td>\n <td>infl</td>\n <td>0.000</td>\n </tr>\n <tr>\n <th>2</th>\n <td>1959-03-31</td>\n <td>unemp</td>\n <td>5.800</td>\n </tr>\n <tr>\n <th>3</th>\n <td>1959-06-30</td>\n <td>realgdp</td>\n <td>2778.801</td>\n </tr>\n <tr>\n <th>4</th>\n <td>1959-06-30</td>\n <td>infl</td>\n <td>2.340</td>\n </tr>\n </tbody>\n</table>\n</div>"
|
||||
},
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": " date item value\n0 1959-03-31 realgdp 2710.349\n1 1959-03-31 infl 0.000\n2 1959-03-31 unemp 5.800\n3 1959-06-30 realgdp 2778.801\n4 1959-06-30 infl 2.340",
|
||||
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>date</th>\n <th>item</th>\n <th>value</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1959-03-31</td>\n <td>realgdp</td>\n <td>2710.349</td>\n </tr>\n <tr>\n <th>1</th>\n <td>1959-03-31</td>\n <td>infl</td>\n <td>0.000</td>\n </tr>\n <tr>\n <th>2</th>\n <td>1959-03-31</td>\n <td>unemp</td>\n <td>5.800</td>\n </tr>\n <tr>\n <th>3</th>\n <td>1959-06-30</td>\n <td>realgdp</td>\n <td>2778.801</td>\n </tr>\n <tr>\n <th>4</th>\n <td>1959-06-30</td>\n <td>infl</td>\n <td>2.340</td>\n </tr>\n </tbody>\n</table>\n</div>"
|
||||
},
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"#请输入data使用stack实现的代码(不得使用melt)\n",
|
||||
"data = data.reset_index()\n",
|
||||
"\n",
|
||||
"ldata= data.set_index('date').stack().reset_index()\n",
|
||||
"ldata.columns = ['date', 'item', 'value']\n",
|
||||
"ldata.head()\n",
|
||||
"\n",
|
||||
"# 请输出data使用melt实现的代码(不得使用stack)\n",
|
||||
"#data = data.reset_index()\n",
|
||||
"#ldata = pd.melt(data, id_vars=['date'], value_vars=['realgdp', 'infl', 'unemp'], var_name='item', value_name='value')\n",
|
||||
"ldata.head()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**作业2**\n",
|
||||
"\n",
|
||||
"ldata通过pivot/unstack恢复data"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 38,
|
||||
"metadata": {
|
||||
"scrolled": true,
|
||||
"ExecuteTime": {
|
||||
"start_time": "2023-05-04T00:56:26.823785Z",
|
||||
"end_time": "2023-05-04T00:56:26.852233Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": " infl realgdp unemp\ndate \n1959-03-31 0.00 2710.349 5.8\n1959-06-30 2.34 2778.801 5.1\n1959-09-30 2.74 2775.488 5.3\n1959-12-31 0.27 2785.204 5.6\n1960-03-31 2.31 2847.699 5.2",
|
||||
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>infl</th>\n <th>realgdp</th>\n <th>unemp</th>\n </tr>\n <tr>\n <th>date</th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>1959-03-31</th>\n <td>0.00</td>\n <td>2710.349</td>\n <td>5.8</td>\n </tr>\n <tr>\n <th>1959-06-30</th>\n <td>2.34</td>\n <td>2778.801</td>\n <td>5.1</td>\n </tr>\n <tr>\n <th>1959-09-30</th>\n <td>2.74</td>\n <td>2775.488</td>\n <td>5.3</td>\n </tr>\n <tr>\n <th>1959-12-31</th>\n <td>0.27</td>\n <td>2785.204</td>\n <td>5.6</td>\n </tr>\n <tr>\n <th>1960-03-31</th>\n <td>2.31</td>\n <td>2847.699</td>\n <td>5.2</td>\n </tr>\n </tbody>\n</table>\n</div>"
|
||||
},
|
||||
"execution_count": 38,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"#请输入ldata使用pivot实现的代码(不得使用unstack)\n",
|
||||
"#pivoted = ldata.pivot(index='date', columns='item', values='value')\n",
|
||||
"#pivoted.head() #同data.head()\n",
|
||||
"\n",
|
||||
"#请输入ldata使用unstack实现的代码(不得使用pivot)\n",
|
||||
"# 将date列转换为索引,并将item列转换为列标签\n",
|
||||
"pivoted = ldata.set_index(['date', 'item'])['value'].unstack()\n",
|
||||
"# 重命名列标签级别的名称\n",
|
||||
"pivoted.columns.name = None\n",
|
||||
"\n",
|
||||
"pivoted.head() #同data.head() "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**作业3:**\n",
|
||||
"\n",
|
||||
"参照“经营数据分析.xlsx”,求解下列问题,使得输出与结果相同"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"start_time": "2023-05-04T15:44:58.159977Z",
|
||||
"end_time": "2023-05-04T15:44:58.196601Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" 方案 设备投资 单件成本 年销售量 销售单价 年收益\n",
|
||||
"0 方案1 1500000 1700 8000 2900 8100000\n",
|
||||
"1 方案2 2000000 1550 8000 2900 8800000\n",
|
||||
"2 方案3 2500000 1400 8000 2900 9500000\n",
|
||||
"年收益最高的方案是: 方案3\n",
|
||||
" 方案 设备投资 单件成本 年销售量 销售单价 年收益 差值\n",
|
||||
"0 方案1 1500000 1700 8000 2900 8100000 1960000090000\n",
|
||||
"1 方案2 2000000 1550 8000 2900 8800000 740000022500\n",
|
||||
"2 方案3 2500000 1400 8000 2900 9500000 1000000000000\n",
|
||||
"差值最小的方案是: 方案2\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": " 畅销 一般 滞销\n方案 \n方案1 12900000 8100000 300000\n方案2 14200000 8800000 25000\n方案3 15500000 9500000 -250000",
|
||||
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>畅销</th>\n <th>一般</th>\n <th>滞销</th>\n </tr>\n <tr>\n <th>方案</th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>方案1</th>\n <td>12900000</td>\n <td>8100000</td>\n <td>300000</td>\n </tr>\n <tr>\n <th>方案2</th>\n <td>14200000</td>\n <td>8800000</td>\n <td>25000</td>\n </tr>\n <tr>\n <th>方案3</th>\n <td>15500000</td>\n <td>9500000</td>\n <td>-250000</td>\n </tr>\n </tbody>\n</table>\n</div>"
|
||||
},
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" 畅销 一般 滞销\n",
|
||||
"0 12900000 8100000 300000\n",
|
||||
"1 14200000 8800000 25000\n",
|
||||
"2 15500000 9500000 -250000\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": " 畅销 一般 滞销 折中\n方案 \n方案1 12900000 8100000 300000 8490000.0\n方案2 14200000 8800000 25000 9238750.0\n方案3 15500000 9500000 -250000 9987500.0",
|
||||
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>畅销</th>\n <th>一般</th>\n <th>滞销</th>\n <th>折中</th>\n </tr>\n <tr>\n <th>方案</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>方案1</th>\n <td>12900000</td>\n <td>8100000</td>\n <td>300000</td>\n <td>8490000.0</td>\n </tr>\n <tr>\n <th>方案2</th>\n <td>14200000</td>\n <td>8800000</td>\n <td>25000</td>\n <td>9238750.0</td>\n </tr>\n <tr>\n <th>方案3</th>\n <td>15500000</td>\n <td>9500000</td>\n <td>-250000</td>\n <td>9987500.0</td>\n </tr>\n </tbody>\n</table>\n</div>"
|
||||
},
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" 畅销 一般 滞销 折中\n",
|
||||
"0 12900000 8100000 300000 8490000.0\n",
|
||||
"1 14200000 8800000 25000 9238750.0\n",
|
||||
"2 15500000 9500000 -250000 9987500.0\n",
|
||||
"折中方案最佳方案是: 方案3\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": " 畅销 一般 滞销 期望\n方案 \n方案1 12900000 8100000 300000 6630000.0\n方案2 14200000 8800000 25000 7146250.0\n方案3 15500000 9500000 -250000 7662500.0",
|
||||
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>畅销</th>\n <th>一般</th>\n <th>滞销</th>\n <th>期望</th>\n </tr>\n <tr>\n <th>方案</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>方案1</th>\n <td>12900000</td>\n <td>8100000</td>\n <td>300000</td>\n <td>6630000.0</td>\n </tr>\n <tr>\n <th>方案2</th>\n <td>14200000</td>\n <td>8800000</td>\n <td>25000</td>\n <td>7146250.0</td>\n </tr>\n <tr>\n <th>方案3</th>\n <td>15500000</td>\n <td>9500000</td>\n <td>-250000</td>\n <td>7662500.0</td>\n </tr>\n </tbody>\n</table>\n</div>"
|
||||
},
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" 畅销 一般 滞销 期望\n",
|
||||
"0 12900000 8100000 300000 6630000.0\n",
|
||||
"1 14200000 8800000 25000 7146250.0\n",
|
||||
"2 15500000 9500000 -250000 7662500.0\n",
|
||||
"期望值最佳方案是: 方案3\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"## 单目标求解\n",
|
||||
"# 年收益=年销售量*(销售单价-单件成本)-设备投资\n",
|
||||
"# 求年收益最佳方案?\n",
|
||||
"df = pd.read_excel(\"../examples/经营数据分析.xlsx\")\n",
|
||||
"# 计算年收益\n",
|
||||
"df['年收益'] = df['年销售量'] * (df['销售单价'] - df['单件成本']) - df['设备投资']\n",
|
||||
"# 按照年收益找最大值,取方案列\n",
|
||||
"best_plan = df.loc[df['年收益'].idxmax(), '方案']\n",
|
||||
"print(df)\n",
|
||||
"print('年收益最高的方案是:', best_plan)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"#\n",
|
||||
"# ## 多目标求解 ----\n",
|
||||
"# 期望值=[min(设备投资),min(单件成本),max(年销售量),max(销售单价),\n",
|
||||
"# max(年收益)];\n",
|
||||
"# 差值=每个方案中,各项数据与期望值的之差的平方和\n",
|
||||
"# 求差值最佳方案?\n",
|
||||
"df = pd.read_excel(\"../examples/经营数据分析.xlsx\")\n",
|
||||
"# 计算年收益\n",
|
||||
"df['年收益'] = df['年销售量'] * (df['销售单价'] - df['单件成本']) - df['设备投资']\n",
|
||||
"# 计算期望值\n",
|
||||
"expected_values = [df['设备投资'].min(), df['单件成本'].min(), df['年销售量'].max(), df['销售单价'].max(), df['年收益'].max()]\n",
|
||||
"# 转换为Series以匹配 df\n",
|
||||
"expected_values = pd.Series(expected_values, index=df.columns[1:])\n",
|
||||
"# 计算差值\n",
|
||||
"df['差值'] = np.sum((df - expected_values) ** 2, axis=1)\n",
|
||||
"# 选择差值最小的方案\n",
|
||||
"best_plan = df.loc[df['差值'].idxmin(), '方案']\n",
|
||||
"# 禁用科学计数法打印\n",
|
||||
"pd.set_option('float_format','{:.0f}'.format)\n",
|
||||
"print(df)\n",
|
||||
"print('差值最小的方案是:', best_plan)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# 不确定性决策分析 ----\n",
|
||||
"## 分析方法\n",
|
||||
"# PLm=pd.DataFrame();# 损益矩阵 ProfitLoss matrix\n",
|
||||
"# PLm['畅销']= 12000*(销售单价-单件成本)-设备投资;\n",
|
||||
"# PLm['一般']= 8000*(销售单价-单件成本)-设备投资;\n",
|
||||
"# PLm['滞销']= 1500*(销售单价-单件成本)-设备投资;\n",
|
||||
"# #\n",
|
||||
"# ## 分析原则----\n",
|
||||
"# # 乐观原则\n",
|
||||
"# lg=损益矩阵三种情况的最大值\n",
|
||||
"#\n",
|
||||
"# # 悲观原则\n",
|
||||
"# bg=损益矩阵三种情况的最小值\n",
|
||||
"#\n",
|
||||
"# # 折中原则\n",
|
||||
"# a=0.65 #65%的乐观概率\n",
|
||||
"# 折中方案= a*lg + (1-a)*bg;\n",
|
||||
"# 求折中最佳方案?\n",
|
||||
"df = pd.read_excel(\"../examples/经营数据分析.xlsx\")\n",
|
||||
"# 计算损益矩阵\n",
|
||||
"PLm = pd.DataFrame()\n",
|
||||
"PLm['畅销'] = 12000 * (df['销售单价'] - df['单件成本']) - df['设备投资']\n",
|
||||
"PLm['一般'] = 8000 * (df['销售单价'] - df['单件成本']) - df['设备投资']\n",
|
||||
"PLm['滞销'] = 1500 * (df['销售单价'] - df['单件成本']) - df['设备投资']\n",
|
||||
"PLm.set_index(df['方案'])\n",
|
||||
"print(PLm)\n",
|
||||
"pd.set_option('float_format', '{:.1f}'.format)\n",
|
||||
"# 计算乐观、悲观和折中方案\n",
|
||||
"mids = []\n",
|
||||
"a = 0.65\n",
|
||||
"for index, row in PLm.iterrows():\n",
|
||||
" mids.append(row.max() * a + (1-a) * row.min())\n",
|
||||
"PLm['折中'] = mids\n",
|
||||
"PLm.set_index(df['方案'])\n",
|
||||
"print(PLm)\n",
|
||||
"best_plan = df.loc[PLm['折中'].idxmax(), '方案']\n",
|
||||
"print('折中方案最佳方案是:',best_plan)\n",
|
||||
"\n",
|
||||
"# # 概率性决策分析 ----\n",
|
||||
"## 期望值法 ----\n",
|
||||
"probE=[0.1,0.65,0.25]; #畅销、一般、滞销的概率\n",
|
||||
"# 期望值=损益矩阵*probE\n",
|
||||
"# 求期望值最佳方案?\n",
|
||||
"df = pd.read_excel(\"../examples/经营数据分析.xlsx\")\n",
|
||||
"# 刷新PLm\n",
|
||||
"PLm = pd.DataFrame()\n",
|
||||
"PLm['畅销'] = 12000 * (df['销售单价'] - df['单件成本']) - df['设备投资']\n",
|
||||
"PLm['一般'] = 8000 * (df['销售单价'] - df['单件成本']) - df['设备投资']\n",
|
||||
"PLm['滞销'] = 1500 * (df['销售单价'] - df['单件成本']) - df['设备投资']\n",
|
||||
"\n",
|
||||
"# 利用numpy的dot乘法求出期望值\n",
|
||||
"expected_values = np.dot(PLm, probE)\n",
|
||||
"PLm['期望'] = expected_values\n",
|
||||
"PLm.set_index(df['方案'])\n",
|
||||
"\n",
|
||||
"# 设为保留一位小数\n",
|
||||
"print(PLm)\n",
|
||||
"best_plan = df.loc[PLm['期望'].idxmax(), '方案']\n",
|
||||
"print('期望值最佳方案是:',best_plan)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"hide_input": false,
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.5"
|
||||
},
|
||||
"toc": {
|
||||
"base_numbering": 1,
|
||||
"nav_menu": {},
|
||||
"number_sections": true,
|
||||
"sideBar": true,
|
||||
"skip_h1_title": false,
|
||||
"title_cell": "Table of Contents",
|
||||
"title_sidebar": "Contents",
|
||||
"toc_cell": false,
|
||||
"toc_position": {},
|
||||
"toc_section_display": true,
|
||||
"toc_window_display": false
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 1
|
||||
}
|
|
@ -1,669 +0,0 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"start_time": "2023-05-04T16:38:46.118916Z",
|
||||
"end_time": "2023-05-04T16:38:46.677858Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"\n",
|
||||
"from IPython.core.interactiveshell import InteractiveShell #执行该代码可以使得当前nb支持多输出\n",
|
||||
"InteractiveShell.ast_node_interactivity = \"all\" \n",
|
||||
"import numpy as np\n",
|
||||
"import pandas as pd \n",
|
||||
"pd.options.display.max_rows = 8 "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**作业**\n",
|
||||
"综合运用stack/unstack,pivot/melt"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 69,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2023-05-04T00:55:08.244550Z",
|
||||
"start_time": "2023-05-04T00:55:08.207092Z"
|
||||
},
|
||||
"scrolled": true
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"item realgdp infl unemp\n",
|
||||
"date \n",
|
||||
"1959-03-31 2710.3 0.0 5.8\n",
|
||||
"1959-06-30 2778.8 2.3 5.1\n",
|
||||
"1959-09-30 2775.5 2.7 5.3\n",
|
||||
"1959-12-31 2785.2 0.3 5.6\n",
|
||||
"... ... ... ...\n",
|
||||
"2008-12-31 13141.9 -8.8 6.9\n",
|
||||
"2009-03-31 12925.4 0.9 8.1\n",
|
||||
"2009-06-30 12901.5 3.4 9.2\n",
|
||||
"2009-09-30 12990.3 3.6 9.6\n",
|
||||
"\n",
|
||||
"[203 rows x 3 columns]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"#有可能是版本问题,需要加入.strftime('%Y-%m-%d')\n",
|
||||
"data = pd.read_csv('macrodata.csv')\n",
|
||||
"#指定数据索引\n",
|
||||
"data.index = pd.PeriodIndex(year=data.year, quarter=data.quarter,name='date').strftime('%Y-%m-%d')\n",
|
||||
"data = data.reindex(columns=pd.Index(['realgdp', 'infl', 'unemp'], name='item'))\n",
|
||||
"print(data)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**作业1:**\n",
|
||||
"data通过stack/melt获得ldata"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 70,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2023-05-04T00:55:09.083067Z",
|
||||
"start_time": "2023-05-04T00:55:09.040601Z"
|
||||
},
|
||||
"scrolled": true
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>date</th>\n",
|
||||
" <th>item</th>\n",
|
||||
" <th>value</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td>1959-03-31</td>\n",
|
||||
" <td>realgdp</td>\n",
|
||||
" <td>2710.3</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td>1959-03-31</td>\n",
|
||||
" <td>infl</td>\n",
|
||||
" <td>0.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td>1959-03-31</td>\n",
|
||||
" <td>unemp</td>\n",
|
||||
" <td>5.8</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>3</th>\n",
|
||||
" <td>1959-06-30</td>\n",
|
||||
" <td>realgdp</td>\n",
|
||||
" <td>2778.8</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>4</th>\n",
|
||||
" <td>1959-06-30</td>\n",
|
||||
" <td>infl</td>\n",
|
||||
" <td>2.3</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" date item value\n",
|
||||
"0 1959-03-31 realgdp 2710.3\n",
|
||||
"1 1959-03-31 infl 0.0\n",
|
||||
"2 1959-03-31 unemp 5.8\n",
|
||||
"3 1959-06-30 realgdp 2778.8\n",
|
||||
"4 1959-06-30 infl 2.3"
|
||||
]
|
||||
},
|
||||
"execution_count": 70,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>date</th>\n",
|
||||
" <th>item</th>\n",
|
||||
" <th>value</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td>1959-03-31</td>\n",
|
||||
" <td>realgdp</td>\n",
|
||||
" <td>2710.3</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td>1959-06-30</td>\n",
|
||||
" <td>realgdp</td>\n",
|
||||
" <td>2778.8</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td>1959-09-30</td>\n",
|
||||
" <td>realgdp</td>\n",
|
||||
" <td>2775.5</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>3</th>\n",
|
||||
" <td>1959-12-31</td>\n",
|
||||
" <td>realgdp</td>\n",
|
||||
" <td>2785.2</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>4</th>\n",
|
||||
" <td>1960-03-31</td>\n",
|
||||
" <td>realgdp</td>\n",
|
||||
" <td>2847.7</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" date item value\n",
|
||||
"0 1959-03-31 realgdp 2710.3\n",
|
||||
"1 1959-06-30 realgdp 2778.8\n",
|
||||
"2 1959-09-30 realgdp 2775.5\n",
|
||||
"3 1959-12-31 realgdp 2785.2\n",
|
||||
"4 1960-03-31 realgdp 2847.7"
|
||||
]
|
||||
},
|
||||
"execution_count": 70,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"#请输入data使用stack实现的代码(不得使用melt)\n",
|
||||
"data = data.reset_index()#重置索引,将旧索引添加为列,并使用新的顺序索引\n",
|
||||
"\n",
|
||||
"ldata= data.set_index('date').stack().reset_index()\n",
|
||||
"ldata.columns = ['date', 'item', 'value']\n",
|
||||
"ldata.head()\n",
|
||||
"\n",
|
||||
"# 请输出data使用melt实现的代码(不得使用stack)\n",
|
||||
"data = data.reset_index()\n",
|
||||
"#id_vars指定不需要被重塑的列,value_vars指定要被转换为新行的列,var_name指定新的行中存储变量名称的列的名称\n",
|
||||
"ldata = pd.melt(data, id_vars=['date'], value_vars=['realgdp', 'infl', 'unemp'], var_name='item', value_name='value')\n",
|
||||
"ldata.head()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**作业2**\n",
|
||||
"\n",
|
||||
"ldata通过pivot/unstack恢复data"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 71,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2023-05-04T00:56:26.852233Z",
|
||||
"start_time": "2023-05-04T00:56:26.823785Z"
|
||||
},
|
||||
"scrolled": true
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th>item</th>\n",
|
||||
" <th>infl</th>\n",
|
||||
" <th>realgdp</th>\n",
|
||||
" <th>unemp</th>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>date</th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>1959-03-31</th>\n",
|
||||
" <td>0.0</td>\n",
|
||||
" <td>2710.3</td>\n",
|
||||
" <td>5.8</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1959-06-30</th>\n",
|
||||
" <td>2.3</td>\n",
|
||||
" <td>2778.8</td>\n",
|
||||
" <td>5.1</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1959-09-30</th>\n",
|
||||
" <td>2.7</td>\n",
|
||||
" <td>2775.5</td>\n",
|
||||
" <td>5.3</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1959-12-31</th>\n",
|
||||
" <td>0.3</td>\n",
|
||||
" <td>2785.2</td>\n",
|
||||
" <td>5.6</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1960-03-31</th>\n",
|
||||
" <td>2.3</td>\n",
|
||||
" <td>2847.7</td>\n",
|
||||
" <td>5.2</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
"item infl realgdp unemp\n",
|
||||
"date \n",
|
||||
"1959-03-31 0.0 2710.3 5.8\n",
|
||||
"1959-06-30 2.3 2778.8 5.1\n",
|
||||
"1959-09-30 2.7 2775.5 5.3\n",
|
||||
"1959-12-31 0.3 2785.2 5.6\n",
|
||||
"1960-03-31 2.3 2847.7 5.2"
|
||||
]
|
||||
},
|
||||
"execution_count": 71,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>infl</th>\n",
|
||||
" <th>realgdp</th>\n",
|
||||
" <th>unemp</th>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>date</th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>1959-03-31</th>\n",
|
||||
" <td>0.0</td>\n",
|
||||
" <td>2710.3</td>\n",
|
||||
" <td>5.8</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1959-06-30</th>\n",
|
||||
" <td>2.3</td>\n",
|
||||
" <td>2778.8</td>\n",
|
||||
" <td>5.1</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1959-09-30</th>\n",
|
||||
" <td>2.7</td>\n",
|
||||
" <td>2775.5</td>\n",
|
||||
" <td>5.3</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1959-12-31</th>\n",
|
||||
" <td>0.3</td>\n",
|
||||
" <td>2785.2</td>\n",
|
||||
" <td>5.6</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1960-03-31</th>\n",
|
||||
" <td>2.3</td>\n",
|
||||
" <td>2847.7</td>\n",
|
||||
" <td>5.2</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" infl realgdp unemp\n",
|
||||
"date \n",
|
||||
"1959-03-31 0.0 2710.3 5.8\n",
|
||||
"1959-06-30 2.3 2778.8 5.1\n",
|
||||
"1959-09-30 2.7 2775.5 5.3\n",
|
||||
"1959-12-31 0.3 2785.2 5.6\n",
|
||||
"1960-03-31 2.3 2847.7 5.2"
|
||||
]
|
||||
},
|
||||
"execution_count": 71,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"#请输入ldata使用pivot实现的代码(不得使用unstack)\n",
|
||||
"pivoted = ldata.pivot(index='date', columns='item', values='value')\n",
|
||||
"pivoted.head() #同data.head()\n",
|
||||
"\n",
|
||||
"#请输入ldata使用unstack实现的代码(不得使用pivot)\n",
|
||||
"# 将date列转换为索引,并将item列转换为列标签\n",
|
||||
"pivoted = ldata.set_index(['date', 'item'])['value'].unstack()\n",
|
||||
"# 重命名列标签级别的名称\n",
|
||||
"pivoted.columns.name = None\n",
|
||||
"\n",
|
||||
"pivoted.head() #同data.head() "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**作业3:**\n",
|
||||
"\n",
|
||||
"参照“经营数据分析.xlsx”,求解下列问题,使得输出与结果相同"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"start_time": "2023-05-04T16:43:49.565864Z",
|
||||
"end_time": "2023-05-04T16:43:49.608312Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" 方案 设备投资 单件成本 年销售量 销售单价 年收益\n",
|
||||
"0 方案1 1500000 1700 8000 2900 8100000\n",
|
||||
"1 方案2 2000000 1550 8000 2900 8800000\n",
|
||||
"2 方案3 2500000 1400 8000 2900 9500000\n",
|
||||
"年收益最高的方案是: 方案3\n",
|
||||
" 方案 设备投资 单件成本 年销售量 销售单价 年收益 差值\n",
|
||||
"0 方案1 1500000 1700 8000 2900 8100000 1960000090000\n",
|
||||
"1 方案2 2000000 1550 8000 2900 8800000 740000022500\n",
|
||||
"2 方案3 2500000 1400 8000 2900 9500000 1000000000000\n",
|
||||
"差值最小的方案是: 方案2\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": " 畅销 一般 滞销\n方案 \n方案1 12900000 8100000 300000\n方案2 14200000 8800000 25000\n方案3 15500000 9500000 -250000",
|
||||
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>畅销</th>\n <th>一般</th>\n <th>滞销</th>\n </tr>\n <tr>\n <th>方案</th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>方案1</th>\n <td>12900000</td>\n <td>8100000</td>\n <td>300000</td>\n </tr>\n <tr>\n <th>方案2</th>\n <td>14200000</td>\n <td>8800000</td>\n <td>25000</td>\n </tr>\n <tr>\n <th>方案3</th>\n <td>15500000</td>\n <td>9500000</td>\n <td>-250000</td>\n </tr>\n </tbody>\n</table>\n</div>"
|
||||
},
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": " 畅销 一般 滞销 折中\n方案 \n方案1 12900000 8100000 300000 8490000.0\n方案2 14200000 8800000 25000 9238750.0\n方案3 15500000 9500000 -250000 9987500.0",
|
||||
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>畅销</th>\n <th>一般</th>\n <th>滞销</th>\n <th>折中</th>\n </tr>\n <tr>\n <th>方案</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>方案1</th>\n <td>12900000</td>\n <td>8100000</td>\n <td>300000</td>\n <td>8490000.0</td>\n </tr>\n <tr>\n <th>方案2</th>\n <td>14200000</td>\n <td>8800000</td>\n <td>25000</td>\n <td>9238750.0</td>\n </tr>\n <tr>\n <th>方案3</th>\n <td>15500000</td>\n <td>9500000</td>\n <td>-250000</td>\n <td>9987500.0</td>\n </tr>\n </tbody>\n</table>\n</div>"
|
||||
},
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"折中方案最佳方案是: 方案3\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": " 畅销 一般 滞销 期望\n方案 \n方案1 12900000 8100000 300000 6630000.0\n方案2 14200000 8800000 25000 7146250.0\n方案3 15500000 9500000 -250000 7662500.0",
|
||||
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>畅销</th>\n <th>一般</th>\n <th>滞销</th>\n <th>期望</th>\n </tr>\n <tr>\n <th>方案</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>方案1</th>\n <td>12900000</td>\n <td>8100000</td>\n <td>300000</td>\n <td>6630000.0</td>\n </tr>\n <tr>\n <th>方案2</th>\n <td>14200000</td>\n <td>8800000</td>\n <td>25000</td>\n <td>7146250.0</td>\n </tr>\n <tr>\n <th>方案3</th>\n <td>15500000</td>\n <td>9500000</td>\n <td>-250000</td>\n <td>7662500.0</td>\n </tr>\n </tbody>\n</table>\n</div>"
|
||||
},
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"期望值最佳方案是: 方案3\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"## 单目标求解\n",
|
||||
"# 年收益=年销售量*(销售单价-单件成本)-设备投资\n",
|
||||
"# 求年收益最佳方案?\n",
|
||||
"df = pd.read_excel(\"经营数据分析.xlsx\")\n",
|
||||
"# 计算年收益\n",
|
||||
"df['年收益'] = df['年销售量'] * (df['销售单价'] - df['单件成本']) - df['设备投资']\n",
|
||||
"# 按照年收益找最大值,取方案列\n",
|
||||
"best_plan = df.loc[df['年收益'].idxmax(), '方案']\n",
|
||||
"print(df)\n",
|
||||
"print('年收益最高的方案是:', best_plan)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"#\n",
|
||||
"# ## 多目标求解 ----\n",
|
||||
"# 期望值=[min(设备投资),min(单件成本),max(年销售量),max(销售单价),\n",
|
||||
"# max(年收益)];\n",
|
||||
"# 差值=每个方案中,各项数据与期望值的之差的平方和\n",
|
||||
"# 求差值最佳方案?\n",
|
||||
"df = pd.read_excel(\"经营数据分析.xlsx\")\n",
|
||||
"# 计算年收益\n",
|
||||
"df['年收益'] = df['年销售量'] * (df['销售单价'] - df['单件成本']) - df['设备投资']\n",
|
||||
"# 计算期望值\n",
|
||||
"expected_values = [df['设备投资'].min(), df['单件成本'].min(), df['年销售量'].max(), df['销售单价'].max(), df['年收益'].max()]\n",
|
||||
"# 转换为Series以匹配 df\n",
|
||||
"expected_values = pd.Series(expected_values, index=df.columns[1:])\n",
|
||||
"\n",
|
||||
"# 计算差值\n",
|
||||
"df['差值'] = np.sum((df - expected_values) ** 2, axis=1)\n",
|
||||
"# 选择差值最小的方案\n",
|
||||
"best_plan = df.loc[df['差值'].idxmin(), '方案']\n",
|
||||
"# 禁用科学计数法打印\n",
|
||||
"pd.set_option('float_format','{:.0f}'.format)\n",
|
||||
"print(df)\n",
|
||||
"print('差值最小的方案是:', best_plan)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# 不确定性决策分析 ----\n",
|
||||
"## 分析方法\n",
|
||||
"# PLm=pd.DataFrame();# 损益矩阵 ProfitLoss matrix\n",
|
||||
"# PLm['畅销']= 12000*(销售单价-单件成本)-设备投资;\n",
|
||||
"# PLm['一般']= 8000*(销售单价-单件成本)-设备投资;\n",
|
||||
"# PLm['滞销']= 1500*(销售单价-单件成本)-设备投资;\n",
|
||||
"# #\n",
|
||||
"# ## 分析原则----\n",
|
||||
"# # 乐观原则\n",
|
||||
"# lg=损益矩阵三种情况的最大值\n",
|
||||
"#\n",
|
||||
"# # 悲观原则\n",
|
||||
"# bg=损益矩阵三种情况的最小值\n",
|
||||
"#\n",
|
||||
"# # 折中原则\n",
|
||||
"# a=0.65 #65%的乐观概率\n",
|
||||
"# 折中方案= a*lg + (1-a)*bg;\n",
|
||||
"# 求折中最佳方案?\n",
|
||||
"df = pd.read_excel(\"经营数据分析.xlsx\")\n",
|
||||
"# 计算损益矩阵\n",
|
||||
"PLm = pd.DataFrame()\n",
|
||||
"PLm['畅销'] = 12000 * (df['销售单价'] - df['单件成本']) - df['设备投资']\n",
|
||||
"PLm['一般'] = 8000 * (df['销售单价'] - df['单件成本']) - df['设备投资']\n",
|
||||
"PLm['滞销'] = 1500 * (df['销售单价'] - df['单件成本']) - df['设备投资']\n",
|
||||
"PLm.set_index(df['方案'])\n",
|
||||
"pd.set_option('float_format', '{:.1f}'.format)\n",
|
||||
"# 计算乐观、悲观和折中方案\n",
|
||||
"mids = []\n",
|
||||
"a = 0.65\n",
|
||||
"for index, row in PLm.iterrows():#返回行索引和行的内容\n",
|
||||
" mids.append(row.max() * a + (1-a) * row.min())\n",
|
||||
"PLm['折中'] = mids\n",
|
||||
"PLm['方案']=df['方案']\n",
|
||||
"PLm.set_index('方案')\n",
|
||||
"best_plan = df.loc[PLm['折中'].idxmax(), '方案']\n",
|
||||
"print('折中方案最佳方案是:',best_plan)\n",
|
||||
"\n",
|
||||
"# # 概率性决策分析 ----\n",
|
||||
"## 期望值法 ----\n",
|
||||
"probE=[0.1,0.65,0.25]; #畅销、一般、滞销的概率\n",
|
||||
"# 期望值=损益矩阵*probE\n",
|
||||
"# 求期望值最佳方案?\n",
|
||||
"df = pd.read_excel(\"经营数据分析.xlsx\")\n",
|
||||
"# 刷新PLm\n",
|
||||
"PLm = pd.DataFrame()\n",
|
||||
"PLm['畅销'] = 12000 * (df['销售单价'] - df['单件成本']) - df['设备投资']\n",
|
||||
"PLm['一般'] = 8000 * (df['销售单价'] - df['单件成本']) - df['设备投资']\n",
|
||||
"PLm['滞销'] = 1500 * (df['销售单价'] - df['单件成本']) - df['设备投资']\n",
|
||||
"\n",
|
||||
"# 利用numpy的dot乘法求出期望值\n",
|
||||
"expected_values = np.dot(PLm, probE)\n",
|
||||
"PLm['期望'] = expected_values\n",
|
||||
"# 设为保留一位小数\n",
|
||||
"PLm['期望']=expected_values\n",
|
||||
"PLm['方案']=df['方案']\n",
|
||||
"PLm.set_index('方案')\n",
|
||||
"best_plan = df.loc[PLm['期望'].idxmax(), '方案']\n",
|
||||
"print('期望值最佳方案是:',best_plan)\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"hide_input": false,
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.10"
|
||||
},
|
||||
"toc": {
|
||||
"base_numbering": 1,
|
||||
"nav_menu": {},
|
||||
"number_sections": true,
|
||||
"sideBar": true,
|
||||
"skip_h1_title": false,
|
||||
"title_cell": "Table of Contents",
|
||||
"title_sidebar": "Contents",
|
||||
"toc_cell": false,
|
||||
"toc_position": {},
|
||||
"toc_section_display": true,
|
||||
"toc_window_display": false
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 1
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
atomicNumber,symbol,name,atomicMass,cpkHexColor,electronicConfiguration,electronegativity,atomicRadius,ionRadius,vanDelWaalsRadius,ionizationEnergy,electronAffinity,oxidationStates,standardState,bondingType,meltingPoint,boilingPoint,density,groupBlock,yearDiscovered
|
||||
1,H,Hydrogen,1.00794(4),FFFFFF,1s1,2.2,37,,120,1312,-73,"-1, 1",gas,diatomic,14,20,0.0000899,nonmetal,1766
|
||||
2,He,Helium,4.002602(2),D9FFFF,1s2,,32,,140,2372,0,,gas,atomic,,4,0.0001785,noble gas,1868
|
||||
3,Li,Lithium,6.941(2),CC80FF,[He] 2s1,0.98,134,76 (+1),182,520,-60,1,solid,metallic,454,1615,0.535,alkali metal,1817
|
||||
4,Be,Beryllium,9.012182(3),C2FF00,[He] 2s2,1.57,90,45 (+2),,900,0,2,solid,metallic,1560,2743,1.848,alkaline earth metal,1798
|
||||
5,B,Boron,10.811(7),FFB5B5,[He] 2s2 2p1,2.04,82,27 (+3),,801,-27,"1, 2, 3",solid,covalent network,2348,4273,2.46,metalloid,1807
|
||||
6,C,Carbon,12.0107(8),909090,[He] 2s2 2p2,2.55,77,16 (+4),170,1087,-154,"-4, -3, -2, -1, 1, 2, 3, 4",solid,covalent network,3823,4300,2.26,nonmetal,Ancient
|
||||
7,N,Nitrogen,14.0067(2),3050F8,[He] 2s2 2p3,3.04,75,146 (-3),155,1402,-7,"-3, -2, -1, 1, 2, 3, 4, 5",gas,diatomic,63,77,0.001251,nonmetal,1772
|
||||
8,O,Oxygen,15.9994(3),FF0D0D,[He] 2s2 2p4,3.44,73,140 (-2),152,1314,-141,"-2, -1, 1, 2",gas,diatomic,55,90,0.001429,nonmetal,1774
|
||||
9,F,Fluorine,18.9984032(5),9.00E+51,[He] 2s2 2p5,3.98,71,133 (-1),147,1681,-328,-1,gas,atomic,54,85,0.001696,halogen,1670
|
||||
10,Ne,Neon,20.1797(6),B3E3F5,[He] 2s2 2p6,,69,,154,2081,0,,gas,atomic,25,27,0.0009,noble gas,1898
|
||||
11,Na,Sodium,22.98976928(2),AB5CF2,[Ne] 3s1,0.93,154,102 (+1),227,496,-53,"-1, 1",solid,metallic,371,1156,0.968,alkali metal,1807
|
||||
12,Mg,Magnesium,24.3050(6),8AFF00,[Ne] 3s2,1.31,130,72 (+2),173,738,0,"1, 2",solid,metallic,923,1363,1.738,alkaline earth metal,1808
|
||||
13,Al,Aluminum,26.9815386(8),BFA6A6,[Ne] 3s2 3p1,1.61,118,53.5 (+3),,578,-43,"1, 3",solid,metallic,933,2792,2.7,metal,Ancient
|
||||
14,Si,Silicon,28.0855(3),F0C8A0,[Ne] 3s2 3p2,1.9,111,40 (+4),210,787,-134,"-4, -3, -2, -1, 1, 2, 3, 4",solid,metallic,1687,3173,2.33,metalloid,1854
|
||||
15,P,Phosphorus,30.973762(2),FF8000,[Ne] 3s2 3p3,2.19,106,44 (+3),180,1012,-72,"-3, -2, -1, 1, 2, 3, 4, 5",solid,covalent network,317,554,1.823,nonmetal,1669
|
||||
16,S,Sulfur,32.065(5),FFFF30,[Ne] 3s2 3p4,2.58,102,184 (-2),180,1000,-200,"-2, -1, 1, 2, 3, 4, 5, 6",solid,covalent network,388,718,1.96,nonmetal,Ancient
|
||||
17,Cl,Chlorine,35.453(2),1FF01F,[Ne] 3s2 3p5,3.16,99,181 (-1),175,1251,-349,"-1, 1, 2, 3, 4, 5, 6, 7",gas,covalent network,172,239,0.003214,halogen,1774
|
||||
18,Ar,Argon,39.948(1),80D1E3,[Ne] 3s2 3p6,,97,,188,1521,0,,gas,atomic,84,87,0.001784,noble gas,1894
|
||||
19,K,Potassium,39.0983(1),8F40D4,[Ar] 4s1,0.82,196,138 (+1),275,419,-48,1,solid,metallic,337,1032,0.856,alkali metal,1807
|
||||
20,Ca,Calcium,40.078(4),3DFF00,[Ar] 4s2,1,174,100 (+2),,590,-2,2,solid,metallic,1115,1757,1.55,alkaline earth metal,Ancient
|
||||
21,Sc,Scandium,44.955912(6),E6E6E6,[Ar] 3d1 4s2,1.36,144,74.5 (+3),,633,-18,"1, 2, 3",solid,metallic,1814,3103,2.985,transition metal,1876
|
||||
22,Ti,Titanium,47.867(1),BFC2C7,[Ar] 3d2 4s2,1.54,136,86 (+2),,659,-8,"-1, 2, 3, 4",solid,metallic,1941,3560,4.507,transition metal,1791
|
||||
23,V,Vanadium,50.9415(1),A6A6AB,[Ar] 3d3 4s2,1.63,125,79 (+2),,651,-51,"-1, 2, 3, 4",solid,metallic,2183,3680,6.11,transition metal,1803
|
||||
24,Cr,Chromium,51.9961(6),8A99C7,[Ar] 3d5 4s1,1.66,127,80 (+2*),,653,-64,"-2, -1, 1, 2, 3, 4, 5, 6",solid,metallic,2180,2944,7.14,transition metal,Ancient
|
||||
25,Mn,Manganese,54.938045(5),9C7AC7,[Ar] 3d5 4s2,1.55,139,67 (+2),,717,0,"-3, -2, -1, 1, 2, 3, 4, 5, 6, 7",solid,metallic,1519,2334,7.47,transition metal,1774
|
||||
26,Fe,Iron,55.845(2),E06633,[Ar] 3d6 4s2,1.83,125,78 (+2*),,763,-16,"-2, -1, 1, 2, 3, 4, 5, 6",solid,metallic,1811,3134,7.874,transition metal,Ancient
|
||||
27,Co,Cobalt,58.933195(5),F090A0,[Ar] 3d7 4s2,1.88,126,74.5 (+2*),,760,-64,"-1, 1, 2, 3, 4, 5",solid,metallic,1768,3200,8.9,transition metal,Ancient
|
||||
28,Ni,Nickel,58.6934(4),50D050,[Ar] 3d8 4s2,1.91,121,69 (+2),163,737,-112,"-1, 1, 2, 3, 4",solid,metallic,1728,3186,8.908,transition metal,1751
|
||||
29,Cu,Copper,63.546(3),C88033,[Ar] 3d10 4s1,1.9,138,77 (+1),140,746,-118,"1, 2, 3, 4",solid,metallic,1358,3200,8.92,transition metal,Ancient
|
||||
30,Zn,Zinc,65.38(2),7D80B0,[Ar] 3d10 4s2,1.65,131,74 (+2),139,906,0,2,solid,metallic,693,1180,7.14,transition metal,1746
|
||||
31,Ga,Gallium,69.723(1),C28F8F,[Ar] 3d10 4s2 4p1,1.81,126,62 (+3),187,579,-29,"1, 2, 3",solid,metallic,303,2477,5.904,metal,1875
|
||||
32,Ge,Germanium,72.64(1),668F8F,[Ar] 3d10 4s2 4p2,2.01,122,73 (+2),,762,-119,"-4, 1, 2, 3, 4",solid,metallic,1211,3093,5.323,metalloid,1886
|
||||
33,As,Arsenic,74.92160(2),BD80E3,[Ar] 3d10 4s2 4p3,2.18,119,58 (+3),185,947,-78,"-3, 2, 3, 5",solid,metallic,1090,887,5.727,metalloid,Ancient
|
||||
34,Se,Selenium,78.96(3),FFA100,[Ar] 3d10 4s2 4p4,2.55,116,198 (-2),190,941,-195,"-2, 2, 4, 6",solid,metallic,494,958,4.819,nonmetal,1817
|
||||
35,Br,Bromine,79.904(1),A62929,[Ar] 3d10 4s2 4p5,2.96,114,196 (-1),185,1140,-325,"-1, 1, 3, 4, 5, 7",liquid,covalent network,266,332,3.12,halogen,1826
|
||||
36,Kr,Krypton,83.798(2),5CB8D1,[Ar] 3d10 4s2 4p6,,110,,202,1351,0,2,gas,atomic,116,120,0.00375,noble gas,1898
|
||||
37,Rb,Rubidium,85.4678(3),702EB0,[Kr] 5s1,0.82,211,152 (+1),,403,-47,1,solid,metallic,312,961,1.532,alkali metal,1861
|
||||
38,Sr,Strontium,87.62(1),00FF00,[Kr] 5s2,0.95,192,118 (+2),,550,-5,2,solid,metallic,1050,1655,2.63,alkaline earth metal,1790
|
||||
39,Y,Yttrium,88.90585(2),94FFFF,[Kr] 4d1 5s2,1.22,162,90 (+3),,600,-30,"1, 2, 3",solid,metallic,1799,3618,4.472,transition metal,1794
|
||||
40,Zr,Zirconium,91.224(2),94E0E0,[Kr] 4d2 5s2,1.33,148,72 (+4),,640,-41,"1, 2, 3, 4",solid,metallic,2128,4682,6.511,transition metal,1789
|
||||
41,Nb,Niobium,92.90638(2),73C2C9,[Kr] 4d4 5s1,1.6,137,72 (+3),,652,-86,"-1, 2, 3, 4, 5",solid,metallic,2750,5017,8.57,transition metal,1801
|
||||
42,Mo,Molybdenum,95.96(2),54B5B5,[Kr] 4d5 5s1,2.16,145,69 (+3),,684,-72,"-2, -1, 1, 2, 3, 4, 5, 6",solid,metallic,2896,4912,10.28,transition metal,1778
|
||||
43,Tc,Technetium,[98],3B9E9E,[Kr] 4d5 5s2,1.9,156,64.5 (+4),,702,-53,"-3, -1, 1, 2, 3, 4, 5, 6, 7",solid,metallic,2430,4538,11.5,transition metal,1937
|
||||
44,Ru,Ruthenium,101.07(2),248F8F,[Kr] 4d7 5s1,2.2,126,68 (+3),,710,-101,"-2, 1, 2, 3, 4, 5, 6, 7, 8",solid,metallic,2607,4423,12.37,transition metal,1827
|
||||
45,Rh,Rhodium,102.90550(2),0A7D8C,[Kr] 4d8 5s1,2.28,135,66.5 (+3),,720,-110,"-1, 1, 2, 3, 4, 5, 6",solid,metallic,2237,3968,12.45,transition metal,1803
|
||||
46,Pd,Palladium,106.42(1),6985,[Kr] 4d10,2.2,131,59 (+1),163,804,-54,"2, 4",solid,metallic,1828,3236,12.023,transition metal,1803
|
||||
47,Ag,Silver,107.8682(2),C0C0C0,[Kr] 4d10 5s1,1.93,153,115 (+1),172,731,-126,"1, 2, 3",solid,metallic,1235,2435,10.49,transition metal,Ancient
|
||||
48,Cd,Cadmium,112.411(8),FFD98F,[Kr] 4d10 5s2,1.69,148,95 (+2),158,868,0,2,solid,metallic,594,1040,8.65,transition metal,1817
|
||||
49,In,Indium,114.818(3),A67573,[Kr] 4d10 5s2 5p1,1.78,144,80 (+3),193,558,-29,"1, 2, 3",solid,metallic,430,2345,7.31,metal,1863
|
||||
50,Sn,Tin,118.710(7),668080,[Kr] 4d10 5s2 5p2,1.96,141,112 (+2),217,709,-107,"-4, 2, 4",solid,metallic,505,2875,7.31,metal,Ancient
|
||||
51,Sb,Antimony,121.760(1),9E63B5,[Kr] 4d10 5s2 5p3,2.05,138,76 (+3),,834,-103,"-3, 3, 5",solid,metallic,904,1860,6.697,metalloid,Ancient
|
||||
52,Te,Tellurium,127.60(3),D47A00,[Kr] 4d10 5s2 5p4,2.1,135,221 (-2),206,869,-190,"-2, 2, 4, 5, 6",solid,metallic,723,1261,6.24,metalloid,1782
|
||||
53,I,Iodine,126.90447(3),940094,[Kr] 4d10 5s2 5p5,2.66,133,220 (-1),198,1008,-295,"-1, 1, 3, 5, 7",solid,covalent network,387,457,4.94,halogen,1811
|
||||
54,Xe,Xenon,131.293(6),429EB0,[Kr] 4d10 5s2 5p6,,130,48 (+8),216,1170,0,"2, 4, 6, 8",gas,atomic,161,165,0.0059,noble gas,1898
|
||||
55,Cs,Cesium,132.9054519(2),57178F,[Xe] 6s1,0.79,225,167 (+1),,376,-46,1,solid,metallic,302,944,1.879,alkali metal,1860
|
||||
56,Ba,Barium,137.327(7),00C900,[Xe] 6s2,0.89,198,135 (+2),,503,-14,2,solid,metallic,1000,2143,3.51,alkaline earth metal,1808
|
||||
57,La,Lanthanum,138.90547(7),70D4FF,[Xe] 5d1 6s2,1.1,169,103.2 (+3),,538,-48,"2, 3",solid,metallic,1193,3737,6.146,lanthanoid,1839
|
||||
58,Ce,Cerium,140.116(1),FFFFC7,[Xe] 4f1 5d1 6s2,1.12,,102 (+3),,534,-50,"2, 3, 4",solid,metallic,1071,3633,6.689,lanthanoid,1803
|
||||
59,Pr,Praseodymium,140.90765(2),D9FFC7,[Xe] 4f3 6s2,1.13,,99 (+3),,527,-50,"2, 3, 4",solid,metallic,1204,3563,6.64,lanthanoid,1885
|
||||
60,Nd,Neodymium,144.242(3),C7FFC7,[Xe] 4f4 6s2,1.14,,129 (+2),,533,-50,"2, 3",solid,metallic,1294,3373,7.01,lanthanoid,1885
|
||||
61,Pm,Promethium,[145],A3FFC7,[Xe] 4f5 6s2,1.13,,97 (+3),,540,-50,3,solid,metallic,1373,3273,7.264,lanthanoid,1947
|
||||
62,Sm,Samarium,150.36(2),8FFFC7,[Xe] 4f6 6s2,1.17,,122 (+2),,545,-50,"2, 3",solid,metallic,1345,2076,7.353,lanthanoid,1853
|
||||
63,Eu,Europium,151.964(1),61FFC7,[Xe] 4f7 6s2,1.2,,117 (+2),,547,-50,"2, 3",solid,metallic,1095,1800,5.244,lanthanoid,1901
|
||||
64,Gd,Gadolinium,157.25(3),45FFC7,[Xe] 4f7 5d1 6s2,1.2,,93.8 (+3),,593,-50,"1, 2, 3",solid,metallic,1586,3523,7.901,lanthanoid,1880
|
||||
65,Tb,Terbium,158.92535(2),30FFC7,[Xe] 4f9 6s2,1.2,,92.3 (+3),,566,-50,"1, 3, 4",solid,metallic,1629,3503,8.219,lanthanoid,1843
|
||||
66,Dy,Dysprosium,162.500(1),1FFFC7,[Xe] 4f10 6s2,1.22,,107 (+2),,573,-50,"2, 3",solid,metallic,1685,2840,8.551,lanthanoid,1886
|
||||
67,Ho,Holmium,164.93032(2),00FF9C,[Xe] 4f11 6s2,1.23,,90.1 (+3),,581,-50,3,solid,metallic,1747,2973,8.795,lanthanoid,1878
|
||||
68,Er,Erbium,167.259(3),0.00E+00,[Xe] 4f12 6s2,1.24,,89 (+3),,589,-50,3,solid,metallic,1770,3141,9.066,lanthanoid,1842
|
||||
69,Tm,Thulium,168.93421(2),00D452,[Xe] 4f13 6s2,1.25,,103 (+2),,597,-50,"2, 3",solid,metallic,1818,2223,9.321,lanthanoid,1879
|
||||
70,Yb,Ytterbium,173.054(5),00BF38,[Xe] 4f14 6s2,1.1,,102 (+2),,603,-50,"2, 3",solid,metallic,1092,1469,6.57,lanthanoid,1878
|
||||
71,Lu,Lutetium,174.9668(1),00AB24,[Xe] 4f14 5d1 6s2,1.27,160,86.1 (+3),,524,-50,3,solid,metallic,1936,3675,9.841,lanthanoid,1907
|
||||
72,Hf,Hafnium,178.49(2),4DC2FF,[Xe] 4f14 5d2 6s2,1.3,150,71 (+4),,659,0,"2, 3, 4",solid,metallic,2506,4876,13.31,transition metal,1923
|
||||
73,Ta,Tantalum,180.94788(2),4DA6FF,[Xe] 4f14 5d3 6s2,1.5,138,72 (+3),,761,-31,"-1, 2, 3, 4, 5",solid,metallic,3290,5731,16.65,transition metal,1802
|
||||
74,W,Tungsten,183.84(1),2194D6,[Xe] 4f14 5d4 6s2,2.36,146,66 (+4),,770,-79,"-2, -1, 1, 2, 3, 4, 5, 6",solid,metallic,3695,5828,19.25,transition metal,1783
|
||||
75,Re,Rhenium,186.207(1),267DAB,[Xe] 4f14 5d5 6s2,1.9,159,63 (+4),,760,-15,"-3, -1, 1, 2, 3, 4, 5, 6, 7",solid,metallic,3459,5869,21.02,transition metal,1925
|
||||
76,Os,Osmium,190.23(3),266696,[Xe] 4f14 5d6 6s2,2.2,128,63 (+4),,840,-106,"-2, -1, 1, 2, 3, 4, 5, 6, 7, 8",solid,metallic,3306,5285,22.61,transition metal,1803
|
||||
77,Ir,Iridium,192.217(3),175487,[Xe] 4f14 5d7 6s2,2.2,137,68 (+3),,880,-151,"-3, -1, 1, 2, 3, 4, 5, 6",solid,metallic,2739,4701,22.65,transition metal,1803
|
||||
78,Pt,Platinum,195.084(9),D0D0E0,[Xe] 4f14 5d9 6s1,2.28,128,86 (+2),175,870,-205,"2, 4, 5, 6",solid,metallic,2041,4098,21.09,transition metal,Ancient
|
||||
79,Au,Gold,196.966569(4),FFD123,[Xe] 4f14 5d10 6s1,2.54,144,137 (+1),166,890,-223,"-1, 1, 2, 3, 5",solid,metallic,1337,3129,19.3,transition metal,Ancient
|
||||
80,Hg,Mercury,200.59(2),B8B8D0,[Xe] 4f14 5d10 6s2,2,149,119 (+1),155,1007,0,"1, 2, 4",liquid,metallic,234,630,13.534,transition metal,Ancient
|
||||
81,Tl,Thallium,204.3833(2),A6544D,[Xe] 4f14 5d10 6s2 6p1,2.04,148,150 (+1),196,589,-19,"1, 3",solid,metallic,577,1746,11.85,metal,1861
|
||||
82,Pb,Lead,207.2(1),575961,[Xe] 4f14 5d10 6s2 6p2,2.33,147,119 (+2),202,716,-35,"-4, 2, 4",solid,metallic,601,2022,11.34,metal,Ancient
|
||||
83,Bi,Bismuth,208.98040(1),9E4FB5,[Xe] 4f14 5d10 6s2 6p3,2.02,146,103 (+3),,703,-91,"-3, 3, 5",solid,metallic,544,1837,9.78,metal,Ancient
|
||||
84,Po,Polonium,[209],AB5C00,[Xe] 4f14 5d10 6s2 6p4,2,,94 (+4),,812,-183,"-2, 2, 4, 6",solid,metallic,527,1235,9.196,metalloid,1898
|
||||
85,At,Astatine,[210],754F45,[Xe] 4f14 5d10 6s2 6p5,2.2,,62 (+7),,920,-270,"-1, 1, 3, 5",solid,covalent network,575,,,halogen,1940
|
||||
86,Rn,Radon,[222],428296,[Xe] 4f14 5d10 6s2 6p6,,145,,,1037,,2,gas,atomic,202,211,0.00973,noble gas,1900
|
||||
87,Fr,Francium,[223],420066,[Rn] 7s1,0.7,,180 (+1),,380,,1,solid,metallic,,,,alkali metal,1939
|
||||
88,Ra,Radium,[226],007D00,[Rn] 7s2,0.9,,148 (+2),,509,,2,solid,metallic,973,2010,5,alkaline earth metal,1898
|
||||
89,Ac,Actinium,[227],70ABFA,[Rn] 6d1 7s2,1.1,,112 (+3),,499,,3,solid,metallic,1323,3473,10.07,actinoid,1899
|
||||
90,Th,Thorium,232.03806(2),00BAFF,[Rn] 6d2 7s2,1.3,,94 (+4),,587,,"2, 3, 4",solid,metallic,2023,5093,11.724,actinoid,1828
|
||||
91,Pa,Protactinium,231.03588(2),00A1FF,[Rn] 5f2 6d1 7s2,1.5,,104 (+3),,568,,"3, 4, 5",solid,metallic,1845,4273,15.37,actinoid,1913
|
||||
92,U,Uranium,238.02891(3),008FFF,[Rn] 5f3 6d1 7s2,1.38,,102.5 (+3),186,598,,"3, 4, 5, 6",solid,metallic,1408,4200,19.05,actinoid,1789
|
||||
93,Np,Neptunium,[237],0080FF,[Rn] 5f4 6d1 7s2,1.36,,110 (+2),,605,,"3, 4, 5, 6, 7",solid,metallic,917,4273,20.45,actinoid,1940
|
||||
94,Pu,Plutonium,[244],006BFF,[Rn] 5f6 7s2,1.28,,100 (+3),,585,,"3, 4, 5, 6, 7",solid,metallic,913,3503,19.816,actinoid,1940
|
||||
95,Am,Americium,[243],545CF2,[Rn] 5f7 7s2,1.3,,126 (+2),,578,,"2, 3, 4, 5, 6",solid,metallic,1449,2284,,actinoid,1944
|
||||
96,Cm,Curium,[247],785CE3,[Rn] 5f7 6d1 7s2,1.3,,97 (+3),,581,,"3, 4",solid,metallic,1618,3383,13.51,actinoid,1944
|
||||
97,Bk,Berkelium,[247],8A4FE3,[Rn] 5f9 7s2,1.3,,96 (+3),,601,,"3, 4",solid,metallic,1323,,14.78,actinoid,1949
|
||||
98,Cf,Californium,[251],A136D4,[Rn] 5f10 7s2,1.3,,95 (+3),,608,,"2, 3, 4",solid,metallic,1173,,15.1,actinoid,1950
|
||||
99,Es,Einsteinium,[252],B31FD4,[Rn] 5f11 7s2,1.3,,,,619,,"2, 3",solid,,1133,,,actinoid,1952
|
||||
100,Fm,Fermium,[257],B31FBA,[Rn] 5f12 7s2,1.3,,,,627,,"2, 3",,,1800,,,actinoid,1952
|
||||
101,Md,Mendelevium,[258],B30DA6,[Rn] 5f13 7s2,1.3,,,,635,,"2, 3",,,1100,,,actinoid,1955
|
||||
102,No,Nobelium,[259],BD0D87,[Rn] 5f14 7s2,1.3,,,,642,,"2, 3",,,1100,,,actinoid,1957
|
||||
103,Lr,Lawrencium,[262],C70066,[Rn] 5f14 7s2 7p1,1.3,,,,,,3,,,1900,,,transition metal,1961
|
||||
104,Rf,Rutherfordium,[267],CC0059,[Rn] 5f14 6d2 7s2,,,,,,,4,,,,,,transition metal,1969
|
||||
105,Db,Dubnium,[268],D1004F,[Rn] 5f14 6d3 7s2,,,,,,,,,,,,,transition metal,1967
|
||||
106,Sg,Seaborgium,[271],D90045,[Rn] 5f14 6d4 7s2,,,,,,,,,,,,,transition metal,1974
|
||||
107,Bh,Bohrium,[272],E00038,[Rn] 5f14 6d5 7s2,,,,,,,,,,,,,transition metal,1976
|
||||
108,Hs,Hassium,[270],E6002E,[Rn] 5f14 6d6 7s2,,,,,,,,,,,,,transition metal,1984
|
||||
109,Mt,Meitnerium,[276],EB0026,[Rn] 5f14 6d7 7s2,,,,,,,,,,,,,transition metal,1982
|
||||
110,Ds,Darmstadtium,[281],,[Rn] 5f14 6d9 7s1,,,,,,,,,,,,,transition metal,1994
|
||||
111,Rg,Roentgenium,[280],,[Rn] 5f14 6d10 7s1,,,,,,,,,,,,,transition metal,1994
|
||||
112,Cn,Copernicium,[285],,[Rn] 5f14 6d10 7s2,,,,,,,,,,,,,transition metal,1996
|
||||
113,Nh,Nihonium,[284],,[Rn] 5f14 6d10 7s2 7p1,,,,,,,,,,,,,post-transition metal,2003
|
||||
114,Fl,Flerovium,[289],,[Rn] 5f14 6d10 7s2 7p2,,,,,,,,,,,,,post-transition metal,1998
|
||||
115,Mc,Moscovium,[288],,[Rn] 5f14 6d10 7s2 7p3,,,,,,,,,,,,,post-transition metal,2003
|
||||
116,Lv,Livermorium,[293],,[Rn] 5f14 6d10 7s2 7p4,,,,,,,,,,,,,post-transition metal,2000
|
||||
117,Ts,Tennessine,[294],,[Rn] 5f14 6d10 7s2 7p5,,,,,,,,,,,,,post-transition metal,2010
|
||||
118,Og,Oganesson,[294],,[Rn] 5f14 6d10 7s2 7p6,,,,,,,,,,,,,,
|
|
|
@ -1,184 +0,0 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"start_time": "2023-05-04T09:29:48.650911Z",
|
||||
"end_time": "2023-05-04T09:29:49.231339Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from IPython.core.interactiveshell import InteractiveShell #执行该代码可以使得当前nb支持多输出\n",
|
||||
"InteractiveShell.ast_node_interactivity = \"all\" \n",
|
||||
"import numpy as np\n",
|
||||
"import pandas as pd \n",
|
||||
"import re "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**作业1**\n",
|
||||
"\n",
|
||||
"利用pandas读入csv数据,求化合物的分子式和质量"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"start_time": "2023-05-04T09:31:30.790867Z",
|
||||
"end_time": "2023-05-04T09:31:34.398474Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"The compand is composed of : ['Calcium', 'Carbon', 'Oxygen']\n",
|
||||
" symbol num name atomicMass\n",
|
||||
"0 Ca 1 Calcium 40.078\n",
|
||||
"1 C 1 Carbon 12.011\n",
|
||||
"2 O 3 Oxygen 15.999\n",
|
||||
"The atomic mass of the compound is 100.0869\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# 元素周期表文件,给出任意一个化学表达式,计算其分子元素和质量。输出结果(不得再用C-O2作为输入):\n",
|
||||
"\n",
|
||||
"import csv\n",
|
||||
"def readTable(fileObj):\n",
|
||||
" # 使用pandas reader读取文件对象\n",
|
||||
" df = pd.read_csv(fileObj, index_col='symbol')\n",
|
||||
" return df\n",
|
||||
" \n",
|
||||
"def parserElement(elementStr, table):\n",
|
||||
" # 用 split 方法分割'-'成为数组\n",
|
||||
" elements = elementStr.split('-')\n",
|
||||
" # 初始化函数作用域内变量\n",
|
||||
" names = []\n",
|
||||
" atomicMass_lst = []\n",
|
||||
" symbols = []\n",
|
||||
" numbers = []\n",
|
||||
" mass = 0\n",
|
||||
" # 遍历数组,找寻元素\n",
|
||||
" for element in elements:\n",
|
||||
" # 用正则表达式分离字母与数字 用join把列表连接\n",
|
||||
" number = ''.join(re.findall(r'\\d+', element))\n",
|
||||
" symbol = ''.join(re.findall(r'[^\\d]+', element))\n",
|
||||
" symbols.append(symbol)\n",
|
||||
" # 将元素名称加入数组\n",
|
||||
" names.append(table.loc[symbol]['name'])\n",
|
||||
" # 索引出质量\n",
|
||||
" atomicMass = eval(re.sub(r'\\([^)]*\\)', '', table.loc[symbol]['atomicMass']))\n",
|
||||
" atomicMass_lst.append(atomicMass)\n",
|
||||
" # 判断数量是否为1\n",
|
||||
" if number:\n",
|
||||
" number = int(number)\n",
|
||||
" else:\n",
|
||||
" number = 1\n",
|
||||
" numbers.append(number)\n",
|
||||
" mass += atomicMass * number\n",
|
||||
" # 新建表格\n",
|
||||
" df = pd.DataFrame()\n",
|
||||
" df['symbol'] = symbols\n",
|
||||
" df['num'] = numbers\n",
|
||||
" df['name'] = names\n",
|
||||
" df['atomicMass'] = atomicMass_lst\n",
|
||||
"\n",
|
||||
" print('The compand is composed of : ', names)\n",
|
||||
" print(df)\n",
|
||||
"\n",
|
||||
" print('The atomic mass of the compound is ', mass)\n",
|
||||
"\n",
|
||||
"fileHandle = open('periodic-table.csv','r')\n",
|
||||
"periodicTable = readTable(fileHandle)\n",
|
||||
"\n",
|
||||
"compountString = input('Input a chemical compound, hyphenated,eg. C-O2:')\n",
|
||||
"parserElement(compountString, periodicTable)\n",
|
||||
"\n",
|
||||
"fileHandle.close()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"outputs": [],
|
||||
"source": [],
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
}
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"hide_input": false,
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.5"
|
||||
},
|
||||
"toc": {
|
||||
"base_numbering": 1,
|
||||
"nav_menu": {},
|
||||
"number_sections": true,
|
||||
"sideBar": true,
|
||||
"skip_h1_title": false,
|
||||
"title_cell": "Table of Contents",
|
||||
"title_sidebar": "Contents",
|
||||
"toc_cell": false,
|
||||
"toc_position": {},
|
||||
"toc_section_display": true,
|
||||
"toc_window_display": false
|
||||
},
|
||||
"varInspector": {
|
||||
"cols": {
|
||||
"lenName": 16,
|
||||
"lenType": 16,
|
||||
"lenVar": 40
|
||||
},
|
||||
"kernels_config": {
|
||||
"python": {
|
||||
"delete_cmd_postfix": "",
|
||||
"delete_cmd_prefix": "del ",
|
||||
"library": "var_list.py",
|
||||
"varRefreshCmd": "print(var_dic_list())"
|
||||
},
|
||||
"r": {
|
||||
"delete_cmd_postfix": ") ",
|
||||
"delete_cmd_prefix": "rm(",
|
||||
"library": "var_list.r",
|
||||
"varRefreshCmd": "cat(var_dic_list()) "
|
||||
}
|
||||
},
|
||||
"types_to_exclude": [
|
||||
"module",
|
||||
"function",
|
||||
"builtin_function_or_method",
|
||||
"instance",
|
||||
"_Feature"
|
||||
],
|
||||
"window_display": false
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.10" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/Êý¾Ý˵Ã÷.txt" charset="ISO-8859-1" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,21 +0,0 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<option name="ignoredErrors">
|
||||
<list>
|
||||
<option value="N802" />
|
||||
<option value="N806" />
|
||||
<option value="N801" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredIdentifiers">
|
||||
<list>
|
||||
<option value="PyQt5.QtWidgets.clicked.*" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
|
@ -1,6 +0,0 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
|
||||
</project>
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/M302.iml" filepath="$PROJECT_DIR$/.idea/M302.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
BIN
M302/M302.zip
|
@ -1,78 +0,0 @@
|
|||
from collections import Counter
|
||||
|
||||
def getRecords(filename) -> []:
|
||||
try:
|
||||
persons = [[]]
|
||||
with open(filename, 'r', encoding='utf-8') as f:
|
||||
lines = f.readlines()
|
||||
index = 0
|
||||
persons_text = lines[1].split('\t')
|
||||
for i in range(len(persons_text) - 1):
|
||||
if persons_text[i+1].startswith('Z'):
|
||||
persons[index].append(persons_text[i])
|
||||
index += 1
|
||||
persons.append([])
|
||||
else:
|
||||
persons[index].append(persons_text[i])
|
||||
return persons
|
||||
|
||||
except IOError as e:
|
||||
print(e, '\nPlease try again')
|
||||
|
||||
def analyzeRecords(records):
|
||||
print('<总人次>', len(records), end=" ")
|
||||
|
||||
times_stat = {}
|
||||
male = 0
|
||||
female = 0
|
||||
male_RBC_total = 0
|
||||
male_WBC_total = 0
|
||||
female_RBC_total = 0
|
||||
female_WBC_total = 0
|
||||
for record in records:
|
||||
zID = record[0]
|
||||
gender = record[1]
|
||||
RBC = eval(record[2])
|
||||
WBC = eval(record[3])
|
||||
#Hb = record[4]
|
||||
#LY = record[5]
|
||||
# 统计次数
|
||||
if zID in times_stat:
|
||||
times_stat[zID] += 1
|
||||
else:
|
||||
times_stat[zID] = 1
|
||||
# 统计男女
|
||||
if gender == '男':
|
||||
male += 1
|
||||
male_RBC_total += RBC
|
||||
male_WBC_total += WBC
|
||||
else:
|
||||
female += 1
|
||||
female_RBC_total += RBC
|
||||
female_WBC_total += WBC
|
||||
|
||||
print('<男女人数>', male, '/', female, end=" ")
|
||||
print('<RBC>{:0.3f}/{:1.3f}'.format(male_RBC_total/male, female_RBC_total/female), end=" ")
|
||||
print('<WBC>{:0.3f}/{:1.3f}'.format(male_WBC_total/male, female_WBC_total/female))
|
||||
|
||||
# 统计人数
|
||||
counter = Counter(times_stat.values())
|
||||
print("<检查人次统计如下>")
|
||||
max_times = max(counter.items())[0]
|
||||
for value, count in sorted(counter.items(),key=lambda x:x[0]):
|
||||
print(f'{value}次{count}人')
|
||||
# 找到次数为最高次的
|
||||
max_times_lst = []
|
||||
for person in times_stat:
|
||||
if times_stat[person] == max_times:
|
||||
max_times_lst.append(person)
|
||||
# 排序 sorted默认升序
|
||||
max_times_lst = sorted(max_times_lst, key=lambda x:x[0])
|
||||
print('<检查', max_times, '次的人编号从小到大排列如下>')
|
||||
for zID in max_times_lst:
|
||||
print(zID)
|
||||
|
||||
if __name__ == '__main__':
|
||||
filename = input("<请输入文件名>")
|
||||
records = getRecords(filename)
|
||||
analyzeRecords(records)
|
|
@ -1,2 +0,0 @@
|
|||
zID Gender RBC(10^12/L) WBC(10^9/L) Hb(g/L) LY(10^9/L)
|
||||
Z000001 男 3.8543 6.6906 156.1351 3.1976
|
|
@ -1,2 +0,0 @@
|
|||
zID Gender RBC(10^12/L) WBC(10^9/L) Hb(g/L) LY(10^9/L)
|
||||
Z000003 女 8.5418 9.2777 146.6490 4.8416 Z000002 女 3.5003 0.4192 123.6035 3.7437 Z000001 男 4.6885 1.9815 163.8840 0.7002
|
|
@ -1,2 +0,0 @@
|
|||
zID Gender RBC(10^12/L) WBC(10^9/L) Hb(g/L) LY(10^9/L)
|
||||
Z000010 男 4.0224 9.7905 136.5197 3.4792 Z000011 男 4.7786 6.7324 129.1999 0.1086 Z000043 女 6.0504 8.2686 127.2782 0.5001 Z000030 女 1.9106 4.6063 122.6804 1.9844 Z000015 男 1.5914 10.0966 111.7144 3.6703 Z000038 女 2.6294 7.3138 121.9451 2.2825 Z000036 男 5.4177 5.5367 145.1475 2.0372 Z000033 男 4.1337 4.3680 134.4502 2.2851 Z000020 女 2.9128 2.8126 156.8516 0.9403 Z000016 女 0.9001 8.8633 137.6296 3.2089 Z000018 男 4.1054 2.8274 126.0920 3.2561 Z000013 男 3.9172 10.1505 138.0053 3.7312 Z000024 男 3.3933 4.5287 124.9847 2.4259 Z000003 女 2.0027 5.0927 138.7247 3.7369 Z000042 女 4.7768 12.5906 138.4560 1.2300 Z000023 男 5.9997 10.5593 139.9406 2.9328 Z000035 女 2.7111 9.6683 137.0609 2.4561 Z000030 女 2.2823 4.1127 155.3371 4.8295 Z000024 男 4.1954 12.4295 131.6136 1.3285 Z000013 男 5.1196 5.5110 144.2287 5.3486 Z000031 女 5.8995 8.2830 135.3623 4.1414 Z000028 男 5.8272 5.2572 150.1703 1.1063 Z000015 男 5.3619 4.9540 153.8149 2.2653 Z000044 男 4.4305 5.7719 132.0353 1.6250 Z000032 女 3.9433 10.1627 139.1092 1.7493 Z000042 女 4.7907 9.0031 127.0224 2.5667 Z000023 男 8.1339 10.2874 155.4771 0.8816 Z000031 女 2.5008 4.0163 128.1123 2.9787 Z000001 女 2.3653 4.6850 142.5660 0.6067 Z000019 男 4.3241 7.6815 148.9888 2.3749 Z000007 男 3.7368 8.8386 116.6403 0.5945 Z000004 男 4.8518 5.6126 131.0019 2.7984 Z000002 女 4.8958 10.9668 132.6811 0.1667 Z000005 男 5.2751 9.3109 161.6172 0.3819 Z000050 女 6.2488 3.9093 128.7634 3.9982 Z000033 男 6.3511 10.0999 147.5251 0.4369 Z000032 女 6.2934 3.2847 141.1230 3.2910 Z000034 女 2.2234 7.0978 126.1401 0.1574 Z000048 女 5.1347 6.6973 152.7368 2.4419 Z000007 男 4.1938 11.5977 131.3463 2.9711 Z000049 男 4.5582 8.9223 144.0952 3.4701 Z000035 女 4.4140 11.4248 131.5937 4.5534 Z000010 男 5.0885 8.8381 141.7697 2.5373 Z000019 男 3.6028 6.8451 138.6353 0.6323 Z000018 男 1.4221 2.4811 125.5427 2.4224 Z000034 女 2.5094 10.0110 145.0148 4.5047 Z000007 男 5.9766 9.5443 143.7075 3.4806 Z000040 女 3.6481 9.3440 153.4178 3.6880 Z000003 女 5.7422 14.9910 133.4316 2.0210 Z000012 女 5.8206 8.0011 108.8653 3.7864
|
|
@ -1,8 +0,0 @@
|
|||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.10" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -1,21 +0,0 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<option name="ignoredErrors">
|
||||
<list>
|
||||
<option value="N802" />
|
||||
<option value="N806" />
|
||||
<option value="N801" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredIdentifiers">
|
||||
<list>
|
||||
<option value="PyQt5.QtWidgets.clicked.*" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|