尝试使用Python从Excel电子表格中删除最上面一行

这是我的第一个问题,所以如果我不遵循完美的礼节,请原谅我。 我一直在寻找一个约6个小时的答案,所以我觉得是时候提问了。 我是Python的新手,我试图用Selenium自动化数据input。 我做得很好,但是卡在从Excel中提取数据的部分。 数据拉不是问题,但告诉我的excel删除最上面一行,或移动到下一个,是。 以下是我的脚本示例:

import pandas as pd from pandas import ExcelWriter import numpy as np xl = pd.ExcelFile('C:\\Users\\Steph_000\\Desktop\\students2.xlsx') xl wr = pd.ExcelWriter('C:\\Users\\Steph_000\\Desktop\\students2.xlsx') xl.sheet_names ['Sheet1'] df = xl.parse('Sheet1') #This reads the sheet into a dataframe df cp = pd.read_excel('C:\\Users\\Steph_000\\Desktop\\students2.xlsx') IDNum = cp[:1] #This pulls the first row as a variable print(IDNum) #This is where it prints to the search bar to look the student up chart = cp[1:] #This pulls everything but the first row as a variable print(chart) df.to_excel(wr, 'Sheet1') wr.save() #This is supposed to overwrite it, but just saves it as blank 

不pipe我做什么,我都无法把它往上移,或者其他任何东西。 我真的很挣扎,很沮丧。 如果需要的话,我将使用与pandas不同的Python包装器,但是我已经尝试过使用openpyxl,xlrd和xlwr来无济于事! 拉我的头发,提前致谢!

看下面的例子:

  • 缺less引擎='xlsxwriter'
  • 缺lesssheet_name ='Sheet1

看这个:

  import pandas as pd #Create a Pandas dataframe from the data. df = pd.DataFrame({'Data': [10, 20, 30, 20, 15, 30, 45]}) # Create a Pandas Excel writer using XlsxWriter as the engine. writer = pd.ExcelWriter('pandas_simple.xlsx', engine='xlsxwriter') # Convert the dataframe to an XlsxWriter Excel object. df.to_excel(writer, sheet_name='Sheet1') # Close the Pandas Excel writer and output the Excel file. writer.save() 

http://xlsxwriter.readthedocs.io/working_with_pandas.html