有人可以解釋這是如何作業的嗎?df.columns = 串列(地圖(str,df.columns))
uj5u.com熱心網友回復:
您的代碼不是將列名轉換為字串的最佳方法,請改用:
df.columns = df.columns.astype(str)
你的代碼:
df.columns = list(map(str, df.columns))
相當于:
df.columns = [str(col) for col in df.columns]
map: 對于df.columns(iterable) 中的每個專案,對其應用函式str但該map函式回傳一個迭代器,因此您需要顯式執行list以生成串列。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/429591.html
