Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Removing Characters: Method 2 | Preprocessing Data: Part I
Analyzing and Visualizing Real-World Data
course content

Зміст курсу

Analyzing and Visualizing Real-World Data

Analyzing and Visualizing Real-World Data

1. Preprocessing Data: Part I
2. Preprocessing Data: Part II
3. Analyzing Data
4. Visualizing Data

Removing Characters: Method 2

As mentioned, there are two ways to remove a character from all column values. The second method uses a lambda function. How does it work? You define a lambda function that removes a certain character/characters from a function variable, and apply it to the selected column. Then you convert obtained values to the necessary type and save them.

Завдання

  1. Define a lambda function with a single argument x that will look for and delete any of the characters '$°C%' from both the left and right sides (using the .strip() method). Assign the function to the rm variable.
  2. Apply the rm function to the 'Fuel_Price' column and then convert it to numerical type (float) using the .astype() method. Assign the obtained result to the same column.
  3. Perform the same actions described in the step 2 for the 'Unemployment' column.
  4. Perform the same actions described in the step 2 for the 'Temperature' column.
  5. Display the first row of the df dataframe and data types of the df dataframe.

Завдання

  1. Define a lambda function with a single argument x that will look for and delete any of the characters '$°C%' from both the left and right sides (using the .strip() method). Assign the function to the rm variable.
  2. Apply the rm function to the 'Fuel_Price' column and then convert it to numerical type (float) using the .astype() method. Assign the obtained result to the same column.
  3. Perform the same actions described in the step 2 for the 'Unemployment' column.
  4. Perform the same actions described in the step 2 for the 'Temperature' column.
  5. Display the first row of the df dataframe and data types of the df dataframe.

Все було зрозуміло?

Секція 1. Розділ 5
toggle bottom row

Removing Characters: Method 2

As mentioned, there are two ways to remove a character from all column values. The second method uses a lambda function. How does it work? You define a lambda function that removes a certain character/characters from a function variable, and apply it to the selected column. Then you convert obtained values to the necessary type and save them.

Завдання

  1. Define a lambda function with a single argument x that will look for and delete any of the characters '$°C%' from both the left and right sides (using the .strip() method). Assign the function to the rm variable.
  2. Apply the rm function to the 'Fuel_Price' column and then convert it to numerical type (float) using the .astype() method. Assign the obtained result to the same column.
  3. Perform the same actions described in the step 2 for the 'Unemployment' column.
  4. Perform the same actions described in the step 2 for the 'Temperature' column.
  5. Display the first row of the df dataframe and data types of the df dataframe.

Завдання

  1. Define a lambda function with a single argument x that will look for and delete any of the characters '$°C%' from both the left and right sides (using the .strip() method). Assign the function to the rm variable.
  2. Apply the rm function to the 'Fuel_Price' column and then convert it to numerical type (float) using the .astype() method. Assign the obtained result to the same column.
  3. Perform the same actions described in the step 2 for the 'Unemployment' column.
  4. Perform the same actions described in the step 2 for the 'Temperature' column.
  5. Display the first row of the df dataframe and data types of the df dataframe.

Все було зрозуміло?

Секція 1. Розділ 5
toggle bottom row

Removing Characters: Method 2

As mentioned, there are two ways to remove a character from all column values. The second method uses a lambda function. How does it work? You define a lambda function that removes a certain character/characters from a function variable, and apply it to the selected column. Then you convert obtained values to the necessary type and save them.

Завдання

  1. Define a lambda function with a single argument x that will look for and delete any of the characters '$°C%' from both the left and right sides (using the .strip() method). Assign the function to the rm variable.
  2. Apply the rm function to the 'Fuel_Price' column and then convert it to numerical type (float) using the .astype() method. Assign the obtained result to the same column.
  3. Perform the same actions described in the step 2 for the 'Unemployment' column.
  4. Perform the same actions described in the step 2 for the 'Temperature' column.
  5. Display the first row of the df dataframe and data types of the df dataframe.

Завдання

  1. Define a lambda function with a single argument x that will look for and delete any of the characters '$°C%' from both the left and right sides (using the .strip() method). Assign the function to the rm variable.
  2. Apply the rm function to the 'Fuel_Price' column and then convert it to numerical type (float) using the .astype() method. Assign the obtained result to the same column.
  3. Perform the same actions described in the step 2 for the 'Unemployment' column.
  4. Perform the same actions described in the step 2 for the 'Temperature' column.
  5. Display the first row of the df dataframe and data types of the df dataframe.

Все було зрозуміло?

As mentioned, there are two ways to remove a character from all column values. The second method uses a lambda function. How does it work? You define a lambda function that removes a certain character/characters from a function variable, and apply it to the selected column. Then you convert obtained values to the necessary type and save them.

Завдання

  1. Define a lambda function with a single argument x that will look for and delete any of the characters '$°C%' from both the left and right sides (using the .strip() method). Assign the function to the rm variable.
  2. Apply the rm function to the 'Fuel_Price' column and then convert it to numerical type (float) using the .astype() method. Assign the obtained result to the same column.
  3. Perform the same actions described in the step 2 for the 'Unemployment' column.
  4. Perform the same actions described in the step 2 for the 'Temperature' column.
  5. Display the first row of the df dataframe and data types of the df dataframe.

Секція 1. Розділ 5
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt