本文整理汇总了Python中pandas.ExcelWriter.writerow方法的典型用法代码示例。如果您正苦于以下问题:Python ExcelWriter.writerow方法的具体用法?Python ExcelWriter.writerow怎么用?Python ExcelWriter.writerow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.ExcelWriter
的用法示例。
在下文中一共展示了ExcelWriter.writerow方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_table
# 需要导入模块: from pandas import ExcelWriter [as 别名]
# 或者: from pandas.ExcelWriter import writerow [as 别名]
def save_table(self, table_format = None):
if table_format is None:
table_format = CONF.get('paths', 'table')
output_dir = CONF.get('paths', 'output_dir')
filename = 'sans-titre.' + table_format
user_path = os.path.join(output_dir, filename)
extension = table_format.upper() + " (*." + table_format + ")"
fname = QFileDialog.getSaveFileName(self,
u"Exporter la table", user_path, extension)
if fname:
CONF.set('paths', 'output_dir', os.path.dirname(str(fname)))
try:
if table_format == "xls":
writer = ExcelWriter(str(fname))
df = self.create_dataframe()
descr = self.create_description()
df.to_excel(writer, "table", index=True, header= False)
descr.to_excel(writer, "description", index = False, header=False)
writer.save()
elif table_format =="csv":
# TODO: use DataFrame's ?
now = datetime.now()
csvfile = open(fname, 'wb')
writer = UnicodeWriter(csvfile, dialect= csv.excel, delimiter=';')
for row in self.data:
if not row.desc in ('root'):
outlist = [row.desc]
for val in row.vals:
outlist.append(locale.str(val))
writer.writerow(outlist)
writer.writerow([u'OpenFisca'])
writer.writerow([u'Calculé le %s à %s' % (now.strftime('%d-%m-%Y'), now.strftime('%H:%M'))])
writer.writerow([u'Système socio-fiscal au %s' % CONF.get('simulation', 'datesim')])
writer.writerow([])
csvfile.close()
except Exception, e:
QMessageBox.critical(
self, "Error saving file", str(e),
QMessageBox.Ok, QMessageBox.NoButton)
示例2: save_table
# 需要导入模块: from pandas import ExcelWriter [as 别名]
# 或者: from pandas.ExcelWriter import writerow [as 别名]
def save_table(self):
table_format = self.table_format
filename = _("Untitled.") + table_format
output_dir = self.get_option('table/export_dir')
user_path = os.path.join(output_dir, filename)
extension = table_format.upper() + " (*." + table_format + ")"
fname = QFileDialog.getSaveFileName(self,
_("Save table"), user_path, extension)
if fname:
output_dir = os.path.dirname(str(fname))
self.set_option('table/export_dir', output_dir)
try:
if table_format == "xls":
writer = ExcelWriter(str(fname))
df = self.create_dataframe()
descr = self.create_description()
df.to_excel(writer, "table", index=True, header= False)
descr.to_excel(writer, "description", index = False, header=False)
writer.save()
elif table_format =="csv":
# TODO: use DataFrame's ?
now = datetime.now()
csvfile = open(fname, 'wb')
writer = UnicodeWriter(csvfile, dialect= csv.excel, delimiter=';')
for row in self.data:
if not row.desc in ('root'):
outlist = [row.desc]
for val in row.vals:
outlist.append(locale.str(val))
writer.writerow(outlist)
writer.writerow(['OpenFisca'])
writer.writerow([_('Computed on %s at %s') % (now.strftime('%d-%m-%Y'), now.strftime('%H:%M'))])
writer.writerow([_('Socio-fiscal legislation of date %s') % str(self.simulation.datesim)])
writer.writerow([])
csvfile.close()
except Exception, e:
QMessageBox.critical(
self, "Error saving file", str(e),
QMessageBox.Ok, QMessageBox.NoButton)