Tag: numpy

将图纸添加到现有的Excel与pandas

我有两个excel文件。 参与者完成实验,并将结果input到另一张表格的两个excel文件中。 这应该发生在每个新的参与者身上。 sheetname是001,002,…,取决于参与者的编号。 但excelfiles只是不断被覆盖。 我正在使用的代码: import pandas allmeans = numpy.array([[(meanreactiontimeinputsusercongruentpositief),(meanreactiontimeinputsusercongruentnegatief),(meanreactiontimeinputsuserincongruentposneg), (meanreactiontimeinputsuserincongruentnegpos), (meanvalueinputusercongruentpositief), (meanvalueinputusercongruentnegatief), (meanreactiontimeinputsuserincongruentposneg), (meanvalueinputuserincongruentnegpos)]]) to_write = pandas.DataFrame({'Age': age, 'Gender': gender, 'MeanReactionTimeCongruentPos': allmeans[:,0], 'MeanReactionTimeCongruentNeg': allmeans[:,1], 'MeanReactionTimeIncongruentPosNeg': allmeans[:,2], 'MeanReactionTimeIncongruentNegPos': allmeans[:,3], 'MeanValueInputCongruentPos': allmeans[:,4], 'MeanValueInputCongruentNeg': allmeans[:,5], 'MeanValueInputIncongruentPosNeg': allmeans[:,6], 'MeanValueIncongruentNegPos': allmeans[:,7]}) to_write.to_excel('MeansOfUsers.xlsx',sheet_name = str(participantnumber), index = False, startrow = 3, startcol = 2) allresults= numpy.array([listofrandomizedconditions,inputsuser,reactiontimesuser]) to_write2 = pandas.DataFrame({'Conditions': […]

将结果写入Excel

我很新的python编程。 我正在尝试使用python xlwt模块来写入结果来优化。 错误是TypeError:'float'对象是不可迭代的。 我无法修复它。 任何人都可以帮助我这个。 我感谢任何帮助。 from math import * import pylab as z; from matplotlib import style import numpy as np; from xlwt import * import xlwt SMALL_FONT =("Verdana", 8) style.use('ggplot') def PriceMovements(S0, down, up, totalsteps, upsteps): S = S0*(pow(up, upsteps))*(pow(down, totalsteps-upsteps)) return S def binomial(d, u, p): g = np.random.binomial(1,p) if g […]

从Numpy Array获取Pandas Dataframe列名

我有一个从excel导入的数据框: >>df Name Emp ID Total Salary ABCDE 0 Mike A001 25000 5000 15000 3000 0 2000 1 John A002 23000 5000 10000 3000 3000 2000 2 Bob A003 21000 5000 15000 0 1000 0 3 Rose A004 20000 5000 10000 2000 1000 20000 4 James A005 10000 5000 0 3000 0 2000 现在我已经使用下面的代码计算了Total Salary子集的总和: […]

访问Pandas / Python中选定单元格的索引/行/列

我应该把具有不平凡function的Excel电子表格转换成一个Web应用程序。 我已经决定和pandas一起工作,我想知道怎样处理这个问题。 我需要做的事情之一是允许人们input一个特定的数字(我们称之为lot_number ),并访问同一行中的其他值。 例如,如果lot_number = 3 ,则不同列中的address_value将为555 Something Street。 所有的lot_numbers和address_value条目是不同的。 我的问题是:我怎样才能访问地址值使用pandas根据lot_number ?

使单元格inputpandas数据框中列的名称

比方说,我有一个数据框(使用pandas数据分析库),看起来像这样: Unnamed Column1: 1 'Puppies' 2 6 3 15 4 13 5 12 我想让数据框看起来像这样: 'Puppies' 1 6 2 15 3 13 4 12 5 80 一个人如何转移一切,包括replace列名的条目。 有没有办法做到这一点?

如何引用numpymatrix作为Excel索引

假设我有这样一个numpymatrix [['first_row' '95' '93' '90' '278'] ['second_row' '88' '500' '400' '988']] 现在,当我说B1*B2这样的东西时,我需要访问matrix的B1和B2索引并执行乘法(与Excel类似)。 我如何在Python中实现这一点? ABCDE 1 [['first_row' '95' '93' '90' '278'] 2 ['second_row' '88' '500' '400' '988']]

在numpy数组中检查nan值

我已经阅读了一些excel文件的列,并将其存储在一个numpy数组中。 对于我在col中的每个索引,我想检查值是否为nan,如果是nan,我将删除col中和另一个数组x中的索引i。 我做了这个, workbook = xlrd.open_workbook('well data.xlsx') sheet=workbook.sheet_by_index(0) col= sheet.col_values(1,1) col= np.array (col) col= col.astype(np.float) for i in range (col.shape [0]): if (np.isnan(col[i])): col=np.delete(col,i) x= np.delete(x,i) 我得到两种types的错误,首先当这个浮点数转换存在col = col.astype(np.float),我得到 if (np.isnan(col[i])): IndexError: index out of bounds 第二,如果我删除浮动转换,我得到这个错误, if (np.isnan(col[i])): TypeError: Not implemented for this type 我知道从一个单一的数组中删除南我可以做到这一点, x = x[numpy.logical_not(numpy.isnan(x))] 但是我的情况是不同的,我想从col中删除nan元素,并且在x中删除相应的元素。 例如,如果col中的索引3是nan,则col和x中的索引3应该被删除。 另外,在我的情况下,浮点转换是必要的。 这是一个更详细的例子, 这些是最初的数组(都有相似的长度): col […]

SciPy使用“eq”约束函数来最小化函数,但不能使用SLSQPalgorithm(最好是GRG)

我正在使用NumPy和SciPy将Excel解算器转换为python,虽然我在技术上已经将其工作,但与结果略有不同。 正在通过公式提供示例数据: array_1 = [ 0.0943417538897551, 0.0799476059590533, 0.0486689860368342, 0.052434296201351 , 0.231614207638357, 0.0808322159046283, 0.0819215585688325, 0.140991841045595, 0.189247534431047 ] matrix_1 = [ [0.0235147682238835, 0.0194641686338689, 0.0116344823277316, 0.0214041868628604, 0.010980242438382, 0.013085897256736, 0.0107928914491097, -0.000350116147653561, 0.000323182155233255], [0.0194641686338689, 0.0227374787807333, 0.0147128129866735, 0.023168038099643, 0.00899606198312112, 0.0108035747784655, 0.00989996824509696, -0.000271072225966624, 0.000337765823991017], [0.0116344823277316, 0.0147128129866735, 0.0265282312707786, 0.0140689757522423, 0.021443195995926, 0.0252024393105442, 0.0187159868856209, 0.000969972826332724, -0.0000408711850838449], [0.0214041868628604, 0.023168038099643, 0.0140689757522423, 0.0288819629130722, 0.00890430456025532, 0.00987603454385401, 0.00914278195359995, -0.000127719476583381, 0.000340663672172775], […]

用俄文字符写入numpy.ndarray文件

我尝试写numpy.ndarray文件。 我用 unique1 = np.unique(df['search_term']) unique1 = unique1.tolist() 然后再试1) edf = pd.DataFrame() edf['term'] = unique1 writer = pd.ExcelWriter(r'term.xlsx', engine='xlsxwriter') edf.to_excel(writer) writer.close() 和2) thefile = codecs.open('domain.txt', 'w', encoding='utf-8') for item in unique: thefile.write("%s\n" % item) 但是,所有返回的UnicodeDecodeError: 'utf8' codec can't decode byte 0xd7 in position 9: invalid continuation byte

循环通过python数组来匹配第二个数组中的多个条件,快速的方法?

我是一个Python的初学者,想知道是否有更快的方法来做这个代码,所以请原谅我的无知。 我有2个Excel表格:一个( 结果 )有大约30,000行唯一的用户id,然后我有30列的问题问题,下面的单元格是空的。 我的第二张( 答案 ),有大约40万行和3列。 第一列有用户标识符,第二列有问题,第三列有来自用户的相应问题的答案。 我想要做的事情本质上是一个索引匹配数组excel函数,我可以通过匹配用户标识和问题来填充表单1中的空白单元格和表单2中的答案。 现在我写了一段代码,但是从表1中处理4列需要花费大约2个小时。我试图弄清楚我的做法是不是完全利用了Numpy的function。 import pandas as pd import numpy as np # Need to take in data from 'answers' and merge it into the 'results' data # Will requiring matching the data based on 'id' in column 1 of 'answers' and the # 'question' in column 2 of […]