开始使用免费开始使用

Chocolate percentages

You would like to bite into the chocolates DataFrame to get analyzing. However, the chocolate percentage is given as a string with the percentage sign. That won't do! It's time to use your new column and row skills to fix that.

chocolates contains, among others, the following columns important for this exercise:

  • cocoa_percentage, containing the cocoa percentage as a string, e.g., "65.5%";
  • location, containing the country where the chocolate was manufactured;
  • bean_location, containing the country where the chocolate bean was grown;
  • rating, containing the average customer rating of the chocolate.

DataFrames package has been loaded for you with the using keyword

本练习是课程的一部分

Data Manipulation in Julia

查看课程

练习说明

  • Create a new column, cocoa, by removing the percentage sign from cocoa_percentage and casting the result as a Float64.
  • Drop the cocoa_percentage column.
  • Reorder the columns so that the order is cocoa,rating,location,bean_location and rewrite the original DataFrame.

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Create a new column for cocoa percentage 
____!(chocolates, ____ => ____ => ____)

# Drop the cocoa_percentage column
____!(chocolates, ____)

# Reorder columns
____!(chocolates, ____)

println(first(chocolates, 5))
编辑并运行代码