I'm having an issue with Panda where its prints the whole date frame multiple times, causing it to slow down and along with that, it prints out the incorrect information when being requested to print out 1 specific item
I'm trying to get 'ETA' to print along with the Customer Names in the same order. I have a Excel Spreadsheet but am unable to match the requested name with the requested ETA. I.e. "WILLIAM KLEIN" "10/12/21" "ROGER FRY" "10/13/21"
is what I want. What I get is "WILLIAM KLEIN" "10/12/21" "ROGER FRY" "10/12/21"
Ect ect, until the next iteration "WILLIAM KLEIN" "10/13/21" "ROGER FRY" "10/13/21"
import pandas as pd
desired_width = 500
workbook = pd.read_excel('jobs2.xlsx', sheet_name="Sheet1") # Set up for the excel sheet
# region Setting Console Boundaries
pd.set_option('display.max_columns', 100)
pd.set_option('display.max_rows', 100)
pd.set_option('display.expand_frame_repr', False)
pd.set_option('max_colwidth', -1)
# endregion
# Setting Value for two weeks out if job is more than two weeks out.
twoWeeksOuts = "25,8,2021"
# Getting information from the Excel Sheet
customerName = workbook["Customer Name"]
eta = workbook["ETA"]
for x in eta:
print("PROACTIVE CONTACT TASK: Called " customerName " to advise of ETA of product for " x.strftime("%b %d %Y") " and that we are still on schedule. Advised Independent PROvider will contact them within two business days of when product is available for installation.")
It prints out 100's of iterations of the same information just with the date changed to match that iteration, which is not by design. I can't even post an example because its so many iterations of different names, same dates. Please assist!
CodePudding user response:
Instead of using two different variables 'Customer Name' and 'eta' separately use in one :
eta = workbook["ETA", "Customer Name"]
for x in eta: print("PROACTIVE CONTACT TASK: Called " x[1] " to advise of ETA of product for " x[0].strftime("%b %d %Y") " and that we are still on schedule. Advised Independent Provider will contact them within two business days of when product is available for installation.")
hope it will work for u
CodePudding user response:
try iterrows()...
for RowIndex , Row in workbook.iterrows() :
print(
"PROACTIVE CONTACT TASK: Called "
Row["customerName"]
" to advise of ETA of product for "
x.strftime("%b %d %Y")
" and that we are still on schedule. Advised Independent PROvider will contact them within two business days of when product is available for installation."
)
and with it i think you can skip :
# Getting information from the Excel Sheet
customerName = workbook["Customer Name"]
eta = workbook["ETA"]
i would type the strftime differently though but with the above i think you can work it out---