# Why did the Units switch from celsius to kelvin when I changed my code here?

**URL:** <https://community.wolfram.com/t/why-did-the-units-switch-from-celsius-to-kelvin-when-i-changed-my-code-here/23495>\
**Category:** Questions\
**Tags:** units\
**Created:** [January 24, 2024, 3:59am UTC](https://community.wolfram.com/t/why-did-the-units-switch-from-celsius-to-kelvin-when-i-changed-my-code-here/23495 "2024-01-24T03:59:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hmhh9020](https://avatars.discourse-cdn.com/v4/letter/h/46a35a/32.png) [@hmhh9020](https://community.wolfram.com/u/hmhh9020)\
**Post date:** [January 24, 2024, 3:59am UTC](https://community.wolfram.com/t/why-did-the-units-switch-from-celsius-to-kelvin-when-i-changed-my-code-here/23495/1 "2024-01-24T03:59:26Z")

</div>

![Screenshot2024-01-23at10.58.17PM.jpg](https://global.discourse-cdn.com/wolfram/original/3X/4/f/4f1ec4420f6ea5729a86ce48e4bbfb6f0a3c3332.jpeg)

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [January 24, 2024, 10:27am UTC](https://community.wolfram.com/t/why-did-the-units-switch-from-celsius-to-kelvin-when-i-changed-my-code-here/23495/2 "2024-01-24T10:27:56Z")

</div>

[tutorial/TemperatureUnits](http://reference.wolfram.com/language/tutorial/TemperatureUnits.html)

There has been a recent change in the behaviour of temperature quantities in Mathematica. It was decided that it does not make much sense to add two celsius temperatures, or to multiply one by a coefficient. The moving average implies just those two steps:

```
MovingAverage[{Quantity[a, "DegreesCelsius"],
  Quantity[b, "DegreesCelsius"]}, 2]

```

and the result is expressed in Kelvins, for which the separate steps make sense. Try this:

```
Quantity[a, "DegreesCelsius"] + Quantity[b, "DegreesCelsius"]

```

Strangely enough, `Mean` is not affected:

```
Mean[{Quantity[a, "DegreesCelsius"],
  Quantity[b, "DegreesCelsius"]}]

```

In your specific case, I would suggest to reconvert the moving averages to Celsius.

---

<div class="post-metadata">

**Author:** ![hmhh9020](https://avatars.discourse-cdn.com/v4/letter/h/46a35a/32.png) [@hmhh9020](https://community.wolfram.com/u/hmhh9020)\
**Post date:** [January 26, 2024, 12:22am UTC](https://community.wolfram.com/t/why-did-the-units-switch-from-celsius-to-kelvin-when-i-changed-my-code-here/23495/3 "2024-01-26T00:22:43Z")

</div>

Thank you for the suggestion!

I was able to fix it with the following code:

```
Grid[{UnitConvert[#1, "DegreesCelsius"], #2} & @@@ 
  Transpose[MapAt[MovingAverage[#, 2] &, HistogramList[data], 1]], 
 Dividers -> All]

```

or

```
Grid[Apply[{UnitConvert[#1, "DegreesCelsius"], #2} &, 
  Transpose[MapAt[MovingAverage[#, 2] &, HistogramList[data], 1]], 1],
  Dividers -> All]

```
