Add column (1)
In the video, Hugo 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.
Diese Übung ist Teil des Kurses
Intermediate Python
Anleitung zur Übung
- Use a
forloop to add a new column, namedCOUNTRY, that contains a uppercase version of the country names in the"country"column. You can use the string methodupper()for this. - To see if your code worked, print out
cars. Don't indent this code, so that it's not part of theforloop.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Import cars data
import pandas as pd
cars = pd.read_csv('cars.csv', index_col = 0)
# Code for loop that adds COUNTRY column
# Print cars
print(cars)