[英]add zero to make all subsets the same size then sum them up and show in excel
我編寫了一個代碼,它將從 excel 文件中獲取數據並生成數據的所有組合。 我能夠做到這一點,但我想在數量較少的子集中添加 0,以便所有子集具有相同數量的值。 然后我想添加所有子集並將值放在每個子集的末尾。 然后我想將它發送到 excel 文件。 關於如何實現它的任何想法。 會有很大幫助的。 感謝您的時間。
import pandas as pd
import numpy as np
import itertools
df = pd.ExcelFile('C:/Users/Desktop/Dc Resistance/Book1.xlsx').parse('Frequency,Voltage, Line')
x=[]
x.append(df['Resistance'])
y= np.array(x)
z=y.flatten()
print(z)
result = [seq for i in range(len(z), 0, -1) for seq in
itertools.combinations(z, i)]
print(result)
col = 0
for row, data in enumerate(result):
worksheet.write_row(row, col, data)
workbook.close()
print (result)
output如下
您可以閱讀 excel 表並使用 fillna:
df = pd.read_excel('c:\\somefolder\\data.xlsx')
df.fillna(0, inplace=True)
#this will create columns that sum the rows
df['sum_rows'] = df.sum(axis=1)
df.to_excel('newdata.xlsx')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.