hotshotgg

导航

pandas的for循环,iterrows方法,遍历标题和行内容

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

# Code for loop that adds COUNTRY column
for lab, row in cars.iterrows():
cars.loc[lab,'COUNTRY'] = str.upper(row['country'])


# Print cars
print(cars)
 

 

 

posted on 2024-07-27 22:40  hotshotgg  阅读(21)  评论(0编辑  收藏  举报