-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathadd-column-(1).py
More file actions
29 lines (23 loc) · 828 Bytes
/
add-column-(1).py
File metadata and controls
29 lines (23 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'''
Add column (1)
100xp
In the video, Filip showed you how to add the length of the country names of the
brics DataFrame in a new column:
for lab, row in brics.iterrows() :
brics.loc[lab, "name_length"] = len(row["country"])
You can do similar things on the cars DataFrame.
Instructions
-Use a for loop to add a new column, named COUNTRY, that contains a uppercase
version of the country names in the "country" column. You can use the string
method upper() for this.
-To see if your code worked, print out cars. Don't indent this code, so that
it's not part of the for loop.
'''
# 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'] = row['country'].upper()
# Print cars
print(cars)