我正在尝试读取Excel并将数据写入带有新列的新Excel中。
这是一个示例Excel this
:请忽略表格式
W
我阅读了此excel,并在数据框中添加了新列:
E
我在新列中添加一个值:
WMeow
我通过以下方式在新的Excel中编写此EMeow
:
class WMeow<T extends W> {
constructor(protected parent: T) {
}
woof() {
this.parent.wmethod()
return '2'
}
}
class W {
meow = new WMeow<W>(this)
wmethod() {
console.log("wmethod")
}
}
class EMeow<T extends E> extends WMeow<T> {
hello() {
this.parent.emethod()
return this.woof()
}
}
class E extends W {
meow = new EMeow(this)
emethod() {
console.log("emethod")
}
}
const x = new E()
console.log(x.meow.hello())
但是在新的excel中,数据看起来像:
module
您会看到+-------+------+------+
| Col1 | Col2 | Col3 |
+-------+------+------+
| Prod1 | "ABC | 100 |
XYZ"
| Prod2 | Test | 200 |
+-------+------+------+
是一行。我希望它像以前的Excel一样多行显示。在新的Excel中写入数据时,我可以在代码中进行哪些更改以保留这种格式?
P.S:在调试时,我发现df = pd.read_excel(module)
df["Status"] = ""
的值为rowIndex = df.index[df['Col1'] == 'Prod1'].tolist()
df.loc[rowIndex, 'Status'] = 'Yes'
,但它仍然写在一行中。
答案 0 :(得分:1)
我在下面的python库中找到了它,它帮助我实现了格式化:
from StyleFrame import StyleFrame, Styler, utils
StyleFrame(df, styler_obj=Styler(horizontal_alignment=utils.horizontal_alignments.left, font = utils.fonts.calibri)).to_excel("output4.xlsx", index = None, header=True).save()