I am reworking a script I built to add values to a .csv file. Towards the bottom I have a check function for duplicate data (if same mm/yyyy and Client Acronym are present in the .csv file, don’t write into the csv file for the data being selected from excel). I this worked with 3 clients I put into the Client as r[‘ABCD’,’AABC’,’DDAC’] into the .isin() function. However, the client list is 100 plus, so I turned it into a list in a different file named clients.py
When I go to call this list in to the client .isin function, it is not reading the list for some reason. Not sure where to start other than a for loop. If that’s the case, I will start working on that.
import pandas as pd
import csv
import openpyxl
from clients import unique_clients_main
import warnings
warnings.simplefilter(action='ignore', category=UserWarning)
actuals_csv = r'C:UsersmmesaDocumentsPython Test FilesExcelClient Actuals.csv'
read_actuals = r"C:UsersmmesaDocumentsPython Test FilesExcelClient Actuals Import.xlsx"
#reading/importing csv file into Pandas data frame
df_actuals = pd.read_csv(actuals_csv)
read_wb = read_actuals
#importing actuals from spreadsheet into dataframe
df_actualsimport = pd.read_excel(
io = read_wb,
sheet_name = "Actuals Import",
usecols='A:E',
skiprows=2,
header=0,
)
#changing data type for the given columns
columns = ['Month Actuals', 'Entity', 'AccountName']
for i in columns:
df_actuals[i] = df_actuals[i].astype('|S')
#creating bool checks for True
Client = df_actuals.astype(str).isin([[unique_clients_main]]).any().any()
Month = df_actuals.astype(str).isin([r'12024']).any().any()
check = [Client == True,
Month == True]
if all(check):
print("Values exist already.")
else:
print("Values don't exist.")
df_actualsimport.to_csv(
actuals_csv,
mode = 'a',
header = False,
encoding = 'utf-8',
index = False,
date_format = '%#m/%d/%Y')