Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
check pandas variable type
#3
Oh! I just got a lesson by isinstance this function.
Thank for your assistance.

(Jun-12-2020, 08:47 AM)buran Wrote: you compare type of the object with str object - that's why it's false.
As per the docs and also PEP8 recommendation, the isinstance() built-in function is recommended for testing the type of an object, because it takes subclasses into account.

import pandas as pd
 
spam = [1,2,3]
df = pd.DataFrame(spam)

# better use isinstance()
print(isinstance(df, pd.DataFrame))
print(isinstance(spam, list))
Reply


Messages In This Thread
check pandas variable type - by cools0607 - Jun-12-2020, 07:47 AM
RE: check pandas variable type - by buran - Jun-12-2020, 08:47 AM
RE: check pandas variable type - by cools0607 - Jun-12-2020, 09:21 AM
RE: check pandas variable type - by buran - Jun-12-2020, 09:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  isinstance() always return true for object type check Yoki91 2 2,603 Jul-22-2020, 06:52 PM
Last Post: Yoki91
  Python - change variable type during program execution ple 1 2,419 Apr-12-2020, 08:43 AM
Last Post: buran
  Type hinting - return type based on parameter micseydel 2 2,526 Jan-14-2020, 01:20 AM
Last Post: micseydel
  How to check hardware type? MuntyScruntfundle 4 3,065 Feb-16-2019, 12:23 PM
Last Post: snippsat
  Storing MySQL BIT Data Type data in python variable krushna 2 3,532 Dec-31-2018, 01:28 AM
Last Post: krushna
  how i can check the input type? Firdaos 3 2,888 Dec-13-2018, 11:39 PM
Last Post: wavic
  how to check for file type in a folder SoulsKeeper 4 5,009 Sep-15-2018, 02:48 PM
Last Post: ichabod801
  What would be a way to check if a variable or class existed in an if? Klar 8 5,183 Dec-28-2017, 08:19 PM
Last Post: nilamo
  check if value of passed variable has uppercase characters in it. wfsteadman 3 3,279 Sep-01-2017, 05:52 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

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