Python Forum
dtype in not working in mad() function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dtype in not working in mad() function
#6
(Jul-20-2019, 08:48 AM)scidam Wrote: Ability to use NaN values with columns of integer type is latest pandas feature (and still experimental).
As of Pandas 0.24.x you can do this, e.g.

import pandas as pd
import numpy as np
diSales= { 2016:{'qtr1':34500,'qtr2':56000,'qtr3':47000,'qtr4':49000},
           2017:{'qtr1':44900,'qtr2':46100,'qtr3':57000,'qtr4':59000},
           2018:{'qtr1':54500,'qtr2':51000,'qtr3':57000,'qtr4':58500},
           2019:{'qtr1':61000}
         }
df = pd.DataFrame(diSales, dtype=pd.Int32Dtype())
df.mad(axis=0)
df.info() returns integer dtype, but df.mad still returns float.

Output:
2016 6062.5 2017 6250.0 2018 2500.0 2019 0.0 dtype: float64

Still showing dtyle : float64 in output after using your code which have line: df = pd.DataFrame(diSales, dtype=pd.Int32Dtype()).why ? What is use of this line ?
Reply


Messages In This Thread
RE: dtype in not working in mad() function - by ift38375 - Jul-21-2019, 04:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  FutureWarning: Logical ops (and, or, xor) between Pandas objects and dtype-less seque NewBiee 5 1,586 Sep-12-2023, 03:15 PM
Last Post: deanhystad
  Pandas replace function not working on datafram with floats bcrypto 1 2,879 Apr-12-2021, 08:59 PM
Last Post: bcrypto
  Data dtype error according to the rule "safe" AndreasMavro 5 9,137 Feb-27-2020, 10:46 PM
Last Post: Pama
  ValueError: Input contains infinity or a value too large for dtype('float64') Rabah_r 1 12,898 Apr-06-2019, 11:08 AM
Last Post: scidam
  numpy dtype anomaly bluefrog 4 3,500 Nov-07-2018, 12:37 AM
Last Post: bluefrog

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020