I am writing a small script to help some colleagues with a excel sheet that they maintain, I am using the Pandas library as I have many times beore.
This time I am getting an error that numpy has no attribute float.
I have checked and see that numpy has depreciated some code. I have also checked, and people are still using Pandas without issue.
I have run pip install pandas --upgrade
to confirm I was running the latest and also added the code to my script:
print("Pandas version:", pd.__version__)
print("Pandas installation path:", pd.__file__)
Which returned that I am using pandas 1.5.3, and is installed where I expected it to be.
I have also upgraded numpy and confirmed to be running the latest version.
So I am unsure what I should be doing next to solve this problem.
Here is my current code:
import pandas as pd
import os
import sys
from datetime import datetime, timedelta
def main():
print("Pandas version:", pd.__version__)
print("Pandas installation path:", pd.__file__)
show_Folder = input("Please provide file path of folder: ")
#prepared_by = input("Bid prepared by: ")
show_code = input("Please provide show code: ")
#Make new folder for summary to be saved.
today = datetime.now()
new_folder_name = "A"
summary_location = get_current(show_Folder)
summary_template = summary_location + "/summary_template.xlsx"
new_folder = str(summary_location +"/") + str(today.strftime('%Y%m%d') + new_folder_name )
while os.path.exists(new_folder):
# Add the next letter of the alphabet to the end of the folder name
new_folder_name = chr(ord(new_folder_name[-1])+1)
new_folder = new_folder[0:-1] + new_folder_name
try:
os.mkdir(new_folder)
print("mkdir Executed")
except:
print("Error: Could not create folder")
sys.exit()
#get summary template location, save a new file in dated folder save new locaiotn as variable for make_summary.
print("*** Loading Summary Template *** ")
template = show_Folder +"/PRODUCTION_RESOURCES/"+"summary_template.xlsx"
shutil.copy(template, new_folder)
os.rename(new_folder+"/summary_template.xlsx", new_folder +"/"+ show_code+ "_SeasonSummary_" + str(today.strftime('%Y%m%d')+".xlsx"))
seasonSummary = new_folder +"/"+ show_code + "_Summary_" + str(today.strftime('%Y%m%d'))+".xlsx"
#loop through bid files
episodes, file_paths = get_bids(show_Folder)
print("There are:", episodes, "Bids in CURRENT folders")
i = 0
for path in file_paths:
make_summary(path,seasonSummary,i)
print(path)
i += 1
def get_current(root_folder):
for dirpath, dirnames, filenames in os.walk(root_folder):
if 'CURRENT' in dirnames:
current_path = os.path.join(dirpath, 'CURRENT')
if os.path.relpath(current_path, root_folder).count(os.sep) == 1:
return current_path
return None
def make_summary(file_path, target_file_path, offset):
# read the source Excel file
source_data = pd.read_excel(file_path, sheet_name=["Coverpage", "Brkdwn"])
# extract the data from the specified cells
data = [
source_data["Brkdwn"].iloc[3:, 9],
source_data["Brkdwn"].iloc[4, 27],
source_data["Brkdwn"].iloc[8, 21],
source_data["Brkdwn"].iloc[5, 27],
source_data["Coverpage"].iloc[18, 7],
source_data["Coverpage"].iloc[22, 8],
source_data["Coverpage"].iloc[22, 7],
source_data["Brkdwn"].iloc[7, 9],
source_data["Brkdwn"].iloc[8, 9],
source_data["Brkdwn"].iloc[8, 9],
source_data["Coverpage"].iloc[28, 7],
]
# read the target Excel file
target_data = pd.read_excel(target_file_path)
# calculate the row number based on the offset
row_num = 14 + offset
# write the data to the target file at the appropriate locations
target_data.iloc[row_num, 14] = data[0].to_list()
target_data.iloc[row_num, 15] = data[1]
target_data.iloc[row_num, 16] = data[2]
target_data.iloc[row_num, 17] = data[3]
target_data.iloc[row_num, 18] = data[4]
target_data.iloc[row_num, 19] = data[5]
target_data.iloc[row_num, 20] = data[6]
target_data.iloc[row_num, 21] = data[7]
target_data.iloc[row_num, 22] = data[8]
target_data.iloc[row_num, 23] = data[9]
target_data.iloc[row_num, 24] = data[10]
# save the updated target file
target_data.to_excel(target_file_path, index=False)
def get_bids(root_folder):
episodes = 0
file_paths = []
print("Retrieving Bids from CURRENT Folders")
for root, dirs, files in os.walk(root_folder):
for i in range(len(root)):
print(f"Progress: {i+1} of {len(root)} directories searched", end="\r")
if "CURRENT" in dirs:
current_folder = os.path.join(root, "CURRENT")
for file in os.listdir(current_folder):
if file.endswith(".xlsm"):
episodes += 1
file_paths.append(os.path.join(current_folder, file))
else:
for d1 in dirs:
path1 = os.path.join(root, d1)
if os.path.isdir(path1):
for d2 in os.listdir(path1):
path2 = os.path.join(path1, d2)
if os.path.isdir(path2):
for d3 in os.listdir(path2):
path3 = os.path.join(path2, d3)
if os.path.isdir(path3) and "CURRENT" in os.listdir(path3):
current_folder = os.path.join(path3, "CURRENT")
for file in os.listdir(current_folder):
if file.endswith(".xlsm"):
episodes += 1
file_paths.append(os.path.join(current_folder, file))
return episodes, sorted(file_paths)
main()