hotshotgg

导航

DataFrame调用其他列内容,新建一列的两种方法,apply更高效

# Import cars data
import pandas as pd
cars = pd.read_csv('cars.csv', index_col = 0)

# Use .apply(str.upper)
#for lab, row in cars.iterrows() :
  #cars.loc[lab, "COUNTRY"] = row["country"].upper()
cars['COUNTRY'] = cars['country'].apply(str.upper)
print(cars)
 

 

posted on 2024-07-27 23:08  hotshotgg  阅读(10)  评论(0编辑  收藏  举报