Tag: python

pandaspython和excel文件

我想写一个excel如下: <table> <tr> <td>user</td><td>4</td><td>Method</td><td>method 1</td> </tr> <tr> <td></td><td>title</td><td>note</td> </tr> <tr> <td></td><td>Hangover</td><td>7</td> </tr> <tr> <td></td><td>…</td><td>…</td> </tr> <tr> <td>user</td><td>4</td><td>Method</td><td>method 2</td> </tr> <tr> <td></td><td>title</td><td>note</td> </tr> <tr> <td></td><td>Lord of the ring</td><td>9</td> </tr> <tr> <td></td><td>…</td><td>…</td> </tr> </table> 所以我做了下面的代码: def get_users_recommandation(users, score_mpm_user, score_mpm_unique_user): writer = pd.ExcelWriter('recommendation.xlsx', engine='xlsxwriter') for user in users: label = pd.DataFrame({'user' : [user], 'method' : "mpm unique"}) label.to_excel(writer, […]

使用python从其他excel的值更改excel文件中的值

我有数据 id 30046 30049 30040 30046 接下来的胜利 id mail 30049 natusya_89_2009@mail.ru 30046 fresh_tea@mail.ru 30040 sedoi7072@mail.ru 我想从1文件更改ID从2 Excel的邮件。 欲望输出 id fresh_tea@mail.ru natusya_89_2009@mail.ru sedoi7072@mail.ru fresh_tea@mail.ru 我试试 for (id1, id2, mail) in zip(ids1, ids2, mails): if id1 == id2: ids1.replace(id1, mail)

大pandas阅读excel格式

在格式化后如何获得电子表格的值? 即时通讯工作与货币格式的电子表格 这例如: ITEM NAME UNIT PRICE item1 USD 99 item2 SGD 45 但“USD”和“SGD”这两个术语是使用excel的格式化function添加的,并且pandas的read_excel函数看不到这些术语。 我会得到的价值,但不是货币的名称。 我只能在电子表格上工作,因为我有各种各样的电子表格,大约有6-7张,我希望有一个pandas(或python)级别的解决scheme,而不是一个Excel级别的解决scheme。 多谢你们。 对丹尼尔来说,这就是我实现'xlrd'引擎的方式,它似乎没有做任何事情。 excel = pd.ExcelFile('itemlist.xlsx', sheetname=None) master = pd.DataFrame(None) for sheet in excel.sheet_names: df = pd.read_excel(excel,sheet,header=2, engine='xlrd') master=master.append(df)

Python,从Excel中拉取语句的循环

我仍然是新的python。 只是想知道是否有一个更简单的方法来完成我的任务。 这是我现在的代码 win = visual.Window([800,800],monitor="testmonitor", units="deg") msg = visual.TextStim(win, text='hello this is a test',pos=[0,+1],color='white') msg.draw() win.flip() core.wait(2) msg = visual.TextStim(win, text='statement 1',pos=[0,+1],color='white') msg.draw() win.flip() core.wait(2) msg = visual.TextStim(win, text='statement 2',pos=[0,+1],color='white') msg.draw() win.flip() core.wait(2) msg = visual.TextStim(win, text='statement 3',pos=[0,+1],color='white') msg.draw() win.flip() core.wait(2) 有没有办法从excel文件中提取语句? 例如:我将有一个循环继续进行,每一轮它将拉动文件中的下一行,而不是必须复制代码,并每次写一个新的语句?

查看一个非常大的CSV文件的一部分?

我有一个〜1.0gb的CSV文件,当试图加载到Excel只是为了查看,Excel崩溃。 我不知道该文件的模式,所以我很难将其加载到R或Python。 该文件包含餐厅评论,并在其中包含逗号。 如何在Windows记事本或Excel中打开文件的一部分(比方说前100行,或1.0mb的值)?

Pyexcel更改单元格值

所以我在所有的Excel项目中都使用了openpyxl ,但现在我必须使用.xls文件,所以我不得不改变库。 我select了pyexcel cuz,它似乎相当简单,并有很好的文档。 所以我经历了创build数百个variables,因为没有.index属性,或者什么东西。 我现在想要做的是读正确的文件中的列,在“数量”列中,并从中获得fe值12 ,然后检查其他文件中的同一列,如果不是12,则将其设置为12 。 简单。 但是我找不到有关在文档中更改单个单元格值的任何字词。 你可以帮我吗?

什么是openpyxl中的等价函数?

在xlrd和xlwt中追加一个工作表的行我可以这样做: Stuff = [] column_count = sheet.ncols – 1 for i in range (0, column_count): Stuff.append([sheet.cell_value(row, i) for row in range(sheet.nrows)]) 我如何做openpyxl的等价物?

xlwt不能写入xls文件?

一直遵循一个指南写入xls文件,并使用exmaple如下: wb = xlwt.Workbook() newsheet=wb.add_sheet('sheet1') newsheet.write('0','0','testing') wb.save(testing.xls) 但是我得到一个错误说: ValueError:行索引为“0”,不允许使用.xls格式 这可能是一个非常愚蠢的问题(但是由于指南显示这是“有效的”,有人知道这是什么原因?

对存储在两个单独文档中的坐标运行True / False语句

还是很新的这一切,所以任何帮助,build议等等,真的很感激。 下面是我的代码: import math import pandas file1 = pandas.read_excel('Book1.xlsx') file2 = pandas.read_excel('Book2.xlsx') file1['RA_diff'] = file2['RA'] – file1['RA'] file1['DEC_diff'] = file2['DEC'] – file1['DEC'] dist = file1.apply(lambda row: math.hypot(row['RA_diff'], row['DEC_diff']), axis=1) if dist.values >= 5: print False elif dist.values <= 5: print True, dist 但是当我运行这个代码时,我得到: ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), […]

频率图与matplotlib

我正在尝试使用matplotlib在Python中自动化频率图来计算出现次数,而不是必须在Excel中手动绘图。 但是,我不能像我在Excel中所做的那样创build类似于图表的类似图表。 Matplotlib可以吗? 在Excel中: 码: #!/usr/bin/python import numpy as np import matplotlib.pyplot as plt from numpy import * import os import sys import csv from random import randint x = [6,0,0,26,0,0,0,0,5,0,7,0,12,12,0,0,0,3,0,5,5,0,10,4,3,5,1,0,2,0,0,1,0,8,0,3,7,1,0,0,0,1,1,0,0,0,0,0,7,16,0,0,0,5] plt.hist(x) plt.title("Frequency diagram") plt.xlabel("Value") plt.ylabel("Frequency") plt.show() 结果(与Excel相比,可读性不如以前,我怎样才能使它与Excel图相似):