我正在處理一個自動使用 py 腳本創建帶有表格的決賽 excel 檔案的專案。
現在我需要將當前作業表的一列與另一作業表的另一列進行比較,然后在當前作業表上創建一個回傳比較是或否的列
CURRENT SHEET:[SvnUsers] firstsheet(當前需要添加的地方)
SECOND SHEET[UserDetails]第二張表
當前作業表在 [SvnUsers] 之后應該如何:[輸出 SvnUsers]
所以,如果元素,我需要將第 1 列“accountName”中的第一個作業表的元素與第二個作業表 column1“Account”的元素進行比較。
如果 sheet1 的元素存在于 sheet2 的 column1 中,則在創建的列“Svnaccount?”上 在 sheet1 上,對于 column1 中當前作業表的指定元素,如果該元素存在于輔助作業表中或不存在,將回傳 Yes。
我是如何開始的: 腳本照片
import pandas as pd
from timestampdirectory import createdir
import os
import time
def svnanalysis():
dest = createdir()
dfSvnUsers = pd.read_excel(os.path.join(dest, "SvnUsers.xlsx"))
dfSvnGroupMembership = pd.read_excel(os.path.join(dest, "SvnGroupMembership.xlsx"))
dfSvnRepoGroupAccess = pd.read_excel(os.path.join(dest, "SvnRepoGroupAccess.xlsx"))
dfsvnReposSize = pd.read_excel(os.path.join(dest, "svnReposSize.xlsx"))
dfsvnRepoLastChangeDate = pd.read_excel(os.path.join(dest, "svnRepoLastChangeDate.xlsx"))
dfUserDetails = pd.read_excel(r"D:\GIT-files\Automate-Stats\SVN_sample_files\CM_UsersDetails.xlsx")
timestr = time.strftime("%Y-%m-%d-")
xlwriter = pd.ExcelWriter(os.path.join(dest,f'{timestr}Usage-SvnAnalysis.xlsx'))
dfUserDetails.to_excel(xlwriter, sheet_name='UserDetails',index = False)
dfSvnUsers.to_excel(xlwriter, sheet_name='SvnUsers', index = False )
dfSvnGroupMembership.to_excel(xlwriter, sheet_name='SvnGroupMembership', index = False )
dfSvnRepoGroupAccess.to_excel(xlwriter, sheet_name='SvnRepoGroupAccess', index = False)
dfsvnReposSize.to_excel(xlwriter, sheet_name='svnReposSize', index = False)
dfsvnRepoLastChangeDate.to_excel(xlwriter, sheet_name='svnRepoLastChangeDate',index= False)
xlwriter.close()
dfUsageSvnAnalysis = pd.read_excel(os.path.join(dest, f'{timestr}Usage-SvnAnalysis.xlsx'), sheet_name='SvnUsers')
dfUsageSvnAnalysis = pd.read_excel(os.path.join(dest, f'{timestr}Usage-SvnAnalysis.xlsx'), sheet_name='UserDetails')
dfUsageSvnAnalysis.insert(2,'SVNaccount?',False)
#here code
#compare elements of('SvnUsers') sheet column1 with ('SvnUserDetails) column1 sheet
#In ('SvnUsers') create column [SVNaccount?] and if the elements of column [users] was found on sheet two return Yes if not return NO
print(dfUsageSvnAnalysis)
svnanalysis()
# 行應該是正確的行
我嘗試使用 wk 并應用 excel 公式,但它不是很好 WK TRY 的腳本照片
uj5u.com熱心網友回復:
感謝您提供如此出色的描述,這應該可以滿足您的要求:
import pandas as pd
# Dataframe from which we want to find out whether a pair exists
caller = pd.read_csv('caller.csv').set_index('id')
# Other dataframe we want to search
other = pd.read_csv('other.csv').set_index('id')
# add a column to caller with true if a match in other is found
caller['match'] = caller.index.isin(other.index)
# replace True with 'Yes' and False with 'No'
caller['match'].replace(True, 'Yes', inplace=True)
caller['match'].replace(False, 'No', inplace=True)
# print the result
print(caller)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/491505.html
標籤:Python python-3.x 擅长 熊猫 pycharm
