我查看了其他示例并實施了它們,但沒有得到正確的結果。我有幾個看起來像這樣的數據框Player_Name 0 J.T. PostonPlayer_Name 0 J.T. Poston我正在嘗試更改名稱以匹配我擁有的另一個 excel 文件,因此我沒有使用 excel 索引手動執行此操作。這是我的代碼。import jsonimport pandas as pdimport osyear = 2018path_to_excel = '/Users/aus10/Desktop/PGA/PGA_Tour_Stats/Tournament_Results_Excel/'+str(year)+''excel_files = [pos_json for pos_json in os.listdir(path_to_excel) if pos_json.endswith('.xlsx')]for files in excel_files: df = pd.read_excel('/Users/aus10/Desktop/PGA/PGA_Tour_Stats/Tournament_Results_Excel/'+str(year)+'/'+files+'') df['Player_Name'].replace(to_replace='J.T. Poston', value='JT Poston') print(df) writer = pd.ExcelWriter('/Users/aus10/Desktop/PGA/PGA_Tour_Stats/Tournament_Results_Excel/'+str(year)+'/'+files+'', engine='xlsxwriter') df.to_excel(writer, sheet_name='Sheet1', index=False) df.style.set_properties(**{'text-align': 'center'}) pd.set_option('display.max_colwidth', 100) pd.set_option('display.width', 1000) writer.save()但是,當我在運行代碼后打開 excel 文件時,名稱沒有改變。.xlsx因為我使用的是文件而不是,是否有我遺漏的東西或我需要的特定方式.csv?
添加回答
舉報
0/150
提交
取消