python 写excel saves报错_Python(Pandas)语法错误无效语法writer.save文件()

我试图让这段代码正常工作,但它有错误:for myname in mn:

mydf = df.loc[df.Teacher_name == myname]

mydf.to_excel(writer, sheet_name = myname)

writer.save()

File "", line 4

writer.save()

^

SyntaxError: invalid syntax

导入=

^{pr2}$

写入程序=writer = pd.ExcelWriter("MyData.xlsx", engine='xlsxwriter')

锰=mn = df['name'].unique().tolist()

mn = ['Teacher A', 'Teacher B', 'Teacher C']

使用以下查询生成df:df = pd.read_csv('XXX.csv', names=['Teacher_name', 'Studen_name','Extra'])

数据框输出:Teacher_name Student_name Extra

1 Teacher A Student 1 xxxx

2 Teacher A Student 2 xxxx

3 Teacher B Student 3 xxxx

4 Teacher C Student 4 xxxx

你可能感兴趣的:(python,写excel,saves报错)