Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using iterrows ( ) to iterate over every observation of a Pandas DataFrame is easy to understand, but not very efficient. On every iteration, you're

Using iterrows() to iterate over every observation of a Pandas DataFrame is easy to understand, but not very efficient. On every iteration, you're creating a new Pandas Series.
If you want to add a column to a DataFrame by calling a function on another column, the iterrows() method in combination with a for loop is not the preferred way to go. Instead, you'll want to use apply().
Compare the iterrows() version with the apply() version to get the same result in the brics DataFrame:
for lab, row in brics.iterrows() :
brics.loc[lab, "name_length"]= len(row["country"])
brics["name_length"]= brics["country"].apply(len)
We can do a similar thing to call the upper() method on every name in the country column. However, upper() is a method, so we'll need a slightly different approach:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+ What typical employee will the IA compare him/

Answered: 1 week ago

Question

What is DDL?

Answered: 1 week ago