Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the following function that takes in a frame and a list of columns to ignore. For all columns that are not ignored, extract a

Complete the following function that takes in a frame and a list of columns to ignore. For all columns that are not ignored, extract a number
from the cell's text and replace the cell's contents with that correctly typed number (either a float or int ). The number should be
converted to an int if the text does not have a decimal point (and is not a percentage). If the cell contains no number, replace it with a
numpy. nan . Convert percentages to normalized floats, e.g., str('37.6%(2017 est.)') turns into float(0.376). Return the passed-
in frame.
For cells with ambiguous data/numbers, it is your job to do your best to honor what that data's author likely intended.
Warning: This is a hard task with no exact answer (as with most tasks in machine learning). Look through the data to find as many
edge cases as you can, turn those into test cases, and see how many you can solve. Start with a simple solution and work up from
there.
def extract_numbers(frame, ignore_columns =[]):
return NotImplemented
print("Cleaning up the numeric values:")
extract_numbers(world_data, ['Country', 'Export commodities'])
As a consequence of what we just did, we also standardized all the NaN values in those columns. Before we could see empty values
represented in several different ways:
' NaN '
'NA'
'total: NA'
"(empty
THis is python3
Now, since any cell that didn't contain a number was replaced with numpy. nan , all numeric cells with missing/empty values are consistent.
Now that we have cleaned up our numeric columns, let's officially tell Pandas the data types for our columns. Because even though most of
our columns now only contains numbers (and numpy. nan ), Pandas still needs to be told what data type each column uses.
image text in transcribed

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

Data Management Databases And Organizations

Authors: Watson Watson

5th Edition

0471715360, 978-0471715368

More Books

Students also viewed these Databases questions

Question

Define the term Working Capital Gap.

Answered: 1 week ago