dimanche 12 juin 2016

Trying to remove top row from excel spreadsheet using Python


this is my first question here so if I don't follow perfect etiquette please forgive me. I have been searching for an answer for about 6 hours so I figured it was time to ask. I'm new to Python, and I'm trying to automate data entry with Selenium. I'm doing well, but stuck at the part where I pull data from Excel. The data pulling isn't the problem, but telling my excel to delete the top row, or move onto the next, is. Here is a sample of my script:

    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

No matter what I do, I can't get it to move up the rows, or anything like that. I'm really struggling and very frustrated. I'll use a different Python wrapper than Pandas if I have to, but I've already tried openpyxl, xlrd, and xlwr to no avail! Pulling my hair out, thanks in advance!


Aucun commentaire:

Enregistrer un commentaire