实现功能

excel表格中有4列数,分别为RMF计算得到的 β,γ,势能面及组态,需要挑选出相同 β 值下势能面最低时的组态。为了减小数据量,先将 β 值保留两位小数。

代码

import xlrd
import xlwt

# read xls file
readfile = xlrd.open_workbook('./beta-gamma-constrain.xlsx')
readsheet = readfile.sheet_by_name('Sheet1')

beta = readsheet.col_values(0)
gamma = readsheet.col_values(1)
energy = readsheet.col_values(2)
config = readsheet.col_values(3)
'''
print(beta)
print(gamma)
print(energy)
print(config)
'''
beta_2f = [round(x, 2) for x in beta]

beta_gamma = dict(zip(beta_2f, gamma))
beta_energy = dict(zip(beta_2f, energy))
beta_config = dict(zip(beta_2f, config))

for i in range(0, len(beta_2f)):
  if energy[i] < beta_energy[beta_2f[i]]:
    beta_gamma[beta_2f[i]] = gamma[i]
    beta_energy[beta_2f[i]] = energy[i]
    beta_config[beta_2f[i]] = config[i]
  else:
    continue

print(beta_gamma)
print(beta_energy)
print(beta_config)

# write xls file
write_excl = xlwt.Workbook(encoding='utf-8')
excl_sheet = write_excl.add_sheet('Sheet1')

j = 0
for key, value in beta_gamma.items():
  excl_sheet.write(j, 0, key)
  excl_sheet.write(j, 1, value)
  excl_sheet.write(j, 2, beta_energy[key])
  excl_sheet.write(j, 3, beta_config[key])
  j = j+1

write_excl.save("xx.xls")

用到的库

xlrd,读取 excel 文件的库,可以读取 xls 和 xlsx 文件。

xlwt,写入 excel 文件的库,只能写成 xls 文件。

思路

将数据按列读出,写入 4 个列表,再组装为字典。由于字典中的 key 值是唯一的,因此该过程只是得到了 β-势能面的字典,但势能面的值不是最小的,需要遍历判断再赋值。最后将结果写入新的 excel 表格。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

标签:
python,处理,excel数据

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com

评论“Python应用实现处理excel数据过程解析”

暂无“Python应用实现处理excel数据过程解析”评论...

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。