0
wo = "C:/temp/temp/WO.xlsx"
dfwo = pd.read_excel(wo)

columnnames = ["TicketID","CreateDate","Status","Summary","CreatedBy","Company"]
main = pd.DataFrame(columns = columnnames)

for i in range(0,15):
    print(i)
    main["TicketID"][i] = dfwo["WO ID"][i]
    main["CreateDate"][i] = dfwo["WO Create TimeStamp"][i]
    main["Status"][i] = dfwo["Status"][i]
    main["Summary"][i] = dfwo["WO Summary"][i]
    main["CreatedBy"][i] = dfwo["Submitter Full Name"][i]
    main["Company"][i] = dfwo["Company"][i]

I am trying to copy selected columns from 1 df to another. dfwo is a df derived from Excel Main is an empty dataframe and has selected columns from dfwo

When I run this code, it gives me the error, "IndexError: index 0 is out of bounds for axis 0 with size 0"

Any suggestions pls?

1 Answer 1

2
wo = "C:/temp/temp/WO.xlsx"
dfwo = pd.read_excel(wo)

columnnames =["TicketID","CreateDate","Status","Summary","CreatedBy","Company"]
main = dfwo[columnnames]
new_col_names =  {
    "TicketID":"WO ID",
    "CreateDate":"WO Create TimeStamp",
    "Status":"Status",
    "Summary":"WO Summary",
    "CreatedBy":"Submitter Full Name",
    "Company":"Company"
}
main.rename(columns = new_col_names,inplace = True)

Sign up to request clarification or add additional context in comments.

2 Comments

Column names in dfwo are not same. I cant keep the names of columns in Main same as dfwo as I plan to combine more df data into Main later.
Thanks @bigbounty. However, do you know what was wrong with the For loop approach?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.