最近在做expansion of datset,所以需要把扩展的dataset写入到excel中
我已经矩阵运算全部搞定,最终输出的是两个输出 labels 和 features
自己整理为以下格式
label = [[0],
[1],
[2],
[3]
]
feature = [
[0.1, 0.2, 0.3, 0.4, 0.5],
[0.11, 0.21, 0.31, 0.41, 0.51],
[0.6, 0.7, 0.8, 0.9, 1.00],
[1.1, 1.2, 1.3, 1.4, 1.5],
]
先是准备用python带的xlrd xlrd 等包来操作感觉真的不太行
换思路,用第三方包openpyxl来操作
pip install openpyxl
官方文档在这里
https://openpyxl.readthedocs.io/en/stable/index.html
废话不多说,show you my code
# coding=utf-8
from openpyxl import Workbook
import numpy as np
wb = Workbook()
ws = wb.create_sheet("che")
label = [[0],
[1],
[2],
[3]
]
feature = [
[0.1, 0.2, 0.3, 0.4, 0.5],
[0.11, 0.21, 0.31, 0.41, 0.51],
[0.6, 0.7, 0.8, 0.9, 1.00],
[1.1, 1.2, 1.3, 1.4, 1.5],
]
#这个地方之所以 变成numpy格式是因为在很多时候我们都是在numpy格式下计算的,模拟一下预处理
label = np.array(label)
feature = np.array(feature)
label_input = []
for l in range(len(label)):
label_input.append(label[l][0])
ws.append(label_input)
for f in range(len(feature[0])):
ws.append(feature[:, f].tolist())
wb.save("chehongshu.xlsx")
结果生成一个excel,最后结果如下图:
openpyxl包用起来是真的方便,对于写入,只需要建立一个LIST进行append就好了,如果excel为空的那append就从第一行开始递增操作,你也可以理解为一个ws.append()操作就相当于写入一行,如果excel为有数据的时候,那写入操作从没有数据的那一行开始写入;这里也说一下本来想用Insert来着但是忽略了一个条件,就是insert有个前提条件就是For example to insert a row at 7 (before the existing row 7):,意思为插入之前你的数据的大小一定是比要插入的行数或者列数大的,也就是说插入只能插到里面,不能在边缘插。
for col in range(len(label)):
print col
ws.insert_cols(col+1)
for index, row in enumerate(ws.rows):
#print row
if index == 0:
#row[col+1].value = label[col][0]
print "label"
print label[col]
else:
print "feature"
print feature[col][index-1]
#row[col+1].value = feature[col][index-1]
def create_data_expansion(path, sheet):
data_init = pd.read_excel(path, sheet)
# print data_init
data_df = pd.DataFrame(data_init)
print data_df
data_df_transponse = data_df.T
label_expansion = np.array(data_df_transponse.index)
label_expansion_l = []
for l in range(len(label_expansion)):
label_expansion_l.append([l])
feature_expansion = np.array(data_df_transponse)
label_expansion = np.array(label_expansion_l)
return label_expansion, feature_expansion
if __name__ == "__main__":
path_name = "excel_demo.xlsx"
sheet_name = "11"
label, feature = create_data_expansion(path_name, sheet_name)
print label
print feature
结果:
文章浏览阅读1.5k次,点赞21次,收藏18次。BeautifulSoup4 属于 BeautifulSoup 系列的第四代版本,BeautifulSoup 是一个可以从 HTML 或 XML 文件中提取数据的 Python 库,这个库能够实现树文档的导航、查找,从而帮助我们提取到网页中所需要的数据。。如果忘记了在哪里安装,请回看 Requests 模块第一篇文章。安装好以后,我们围绕数据提取这个话题对 BeautifulSoup4 进行剖析。"""# 问题一:使用标签选择器获取源代码中所有的 p 标签。_beautifulsoup4库 获取br
文章浏览阅读1.9k次。基于Red Hat Enterprise Linux Server release 7.4 (Maipo)最小化安装将会慢慢补齐每个包的作用:1 bash-completion-2.1-6.el7.noarch https://cbs.centos.org/koji/rpminfo?rpmID=4260 2 grubby-8.28-23.el7.x86_64 ..._cannot install both libpng-2:1.5.13-8.el7.x86_64 and libpng-2:1.6.37-1.ky10.
文章浏览阅读2.1k次。这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入欢迎使用Ma..._vxworks rtp
文章浏览阅读185次。以进行加法和减法为例,用户层将要进行的操作码和参数,返回缓冲发给驱动,驱动进行处理并将结果写到返回缓冲中driver.c//_stdcall#include<ntddk.h>#include<ntstrsafe.h>#pragma code_seg("INT")#define SynLinkName L"\\??\\freesec_tx..._pirpstack->majorfunction
文章浏览阅读91次。http://raymond1860.spaces.live.com/Blog/cns!BF47B6FD104579C9!797.entry1.目录树/framework/base/api/framework/base/awt/framework/base/build/framework/base/camera关 于camera的HAL接口库。最终生成native共享库l..._android framework cmds 开发
文章浏览阅读82次。免费领取项目源码,请关注●点赞收藏并私信博主,谢谢-、互联网美食分享平台采用Java技术,Mysql数据库存储数据,基于Springboot框架开发。系统采用了模块化设计方法,根据用户的需求开发功能模块,方便了程序扩展维护,以便后期的更新。整个开发过程首先对系统进行需求分析,得出系统主要功能模块。接着对系统进行总体设计和详细设计。最后对系统进行了功能测试,并对测试结果进行了分析总结,得出系统的不足及需要改进的地方,为以后的系统维护提供了方便,同时也为以后开发类似系统提供了借鉴和帮助。
文章浏览阅读317次。E - Mafia CodeForces - 348A 【二分】One day n friends gathered together to play “Mafia”. During each round of the game some player must be the supervisor and other n - 1 people take part in the game. Fo..._348a二分
文章浏览阅读1.6w次。四元数和旋转矩阵Quaternion(四元数)Quaternion 的定义四元数一般定义如下: q=w+xi+yj+zk其中 w,x,y,z是实数。同时,有: i*i=-1 j*j=-1 k*k=-1四元数也可以表示为: q=[w,v]其中v=(x,y,z)是矢量,w是标量,虽然v是矢量,但不能简_四元数 旋转矩阵
文章浏览阅读5.8w次,点赞6次,收藏3次。很多人在使用海康威视的开发包的时候,都会遇到下面几个问题在安装WebComponents.exe之后 浏览器在运行的时候提示WebComponents.exe为安装 或者是WebComponents.exe不是最新版本开发包提供的版本如下,浏览器自动安装的版本为3.0.5.34这2个版本都是是可以使用的 ,而且不需要更新那么问题就在浏览器了_webcomponents.exe
文章浏览阅读1.4w次,点赞5次,收藏42次。 集成测试与系统测试_集成测试是系统测试吗
文章浏览阅读792次,点赞9次,收藏8次。Jenkins 是一个开源自动化服务器。Jenkins 用户手册。_jenkins官网
文章浏览阅读1.7k次,点赞29次,收藏23次。location,rewrite基于:域名、客户端ip、旧域名、参数匹配,跳转_nginx location直接指向某个网页