Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have two data frames , which I am trying to compare using <assert_frame_equal> . The comparison is failing over few columns which have timestamp values.The value seems to be same :

     DF1     TIME    1970-01-01 02:00:00
             Name: 4, dtype: object
             ----
     DF2     TIME    1970-01-01 02:00:00
             Name: 4, dtype: object

I checked the class of this column :

    DF1  :    <class 'pandas._libs.tslibs.timestamps.Timestamp'>
        ---
    DF2:      <class 'str'>

Error Message from using assert_frame_equal:

DataFrame Expected type <class 'pandas.core.frame.DataFrame'>, found <class 'pandas._libs.tslibs.timestamps.Timestamp'> instead

Can somebody please help , how can I make the classes of two dataframes same. My end goal is just to verify data , (no data types/classes etc). I can't give column name specifically as I have to use this function for multiple data frames , where column names for Date values vary.

question from:https://stackoverflow.com/questions/65933245/convert-the-class-of-one-dataframe-based-on-another-dataframe-classes

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
80 views
Welcome To Ask or Share your Answers For Others

1 Answer

you could avoid dataframe class comparison by turning this flag off : check_frame_type

for more info check this out: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.testing.assert_frame_equal.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...