TransWikia.com

More Issues With Units

Mathematica Asked by fiz on June 7, 2021

I have asked a couple questions here (and received terrific answers), and used that info.

I am trying to fulfill a request from a colleague that liked the results of Astronomy info I had done, but wanted it in a flat, 2D format (along with sun and mood data, but one task at a time.

I manged the grid ok enough (attached), but once again I cannot change the units associated with these quantities from g/cm^3 to kg/m^3. I have tried what others helped with in my previous questions, but, for whatever reason I’m not getting it….and if it’s me, well, that’s possible, but I am trying.

Can the units be changed, and if so how, because I am (once again) out of ideas. I have been looking at this in the documentation and online for a few days now and it’s escaping me.

Thanks (again) for your help.

enter image description here

2 Answers

data = PlanetData[PlanetData[], {"Name", "Density"}] /. {p_, m_} :> {p, UnitConvert[m, "SIBase"]} // 
         Prepend[{"Name", "Density"}]

Grid[data, Frame -> All, Background -> LightYellow, ItemStyle -> {Automatic, 1 -> Bold}]

enter image description here

Correct answer by Rohit Namjoshi on June 7, 2021

With a little more color:

Clear["Global`*"]

items = {"Image", "Name", "Density"};

(data = PlanetData[PlanetData[], items] /. 
     q_Quantity :> UnitConvert[q] // Prepend[items]) //
 Grid[#, Frame -> All, Background -> LightYellow, 
   ItemStyle -> {Automatic, 1 -> Bold}] &

enter image description here

Answered by Bob Hanlon on June 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP