[問題] 使用upper()在Dataframe新增一欄資料
Hi 最近在做練習題
有一題是要在Pandas Dataframe新增一欄資料 COUNTRY
欄位country的大寫
程式碼如下:
import pandas as pdcars = pd.read_csv('cars.csv', index_col = 0)
# Use.apply(str.upper)
cars["COUNTRY"] = cars["country"].apply(str.upper)
print(cars)
Output:
https://imgur.com/h7j7QFz

請問一下為什麼apply()裡是放str.upper
整個程式碼又沒有str的宣告
怎麼知道str 就是指每一個country
感謝解答~~~
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 207.181.219.248
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1514262577.A.404.html
推
12/26 12:43,
8年前
, 1F
12/26 12:43, 1F
→
12/26 13:19,
8年前
, 2F
12/26 13:19, 2F
→
12/26 13:20,
8年前
, 3F
12/26 13:20, 3F
→
12/26 13:20,
8年前
, 4F
12/26 13:20, 4F
→
12/26 16:42,
8年前
, 5F
12/26 16:42, 5F
→
12/26 16:45,
8年前
, 6F
12/26 16:45, 6F
→
12/26 16:47,
8年前
, 7F
12/26 16:47, 7F
推
12/27 06:54,
8年前
, 8F
12/27 06:54, 8F
→
12/27 06:54,
8年前
, 9F
12/27 06:54, 9F
→
12/27 06:55,
8年前
, 10F
12/27 06:55, 10F
→
12/27 09:56,
8年前
, 11F
12/27 09:56, 11F
→
12/27 09:59,
8年前
, 12F
12/27 09:59, 12F
→
12/27 10:00,
8年前
, 13F
12/27 10:00, 13F
→
12/27 10:01,
8年前
, 14F
12/27 10:01, 14F