python + pandas: convert class to json, but ignore dataframe member -
[This issue was able to reproduce, so being updated ..] I have a Jason JSON I'm using Jason to change in The object contains a member property which is the type of pandal. Dataframe (which does not care to serialize me, but want to have a reference). The following snippet indicates the problem that first serialization works for JSN, but the second produces an error:
Import JSN Import Ponds as PP Imports as NP Class myClass : Def __init __ (self, df, title, description, some_arr): Self.title = title self.descr = description self .ar = some_arr self.df = df if __name__ == "__main__": df = pd.DataFrame ( Np.random.randn (10, 5), column = ['A', 'B', 'C', 'D', 'E']) MC1 = Myllus (DF, 'Title', 'Dod' [1,2,3,4]) json_data = json.dumps ( Mc1, default = lambda o: o .__ dict__) #Works Fine df = df [['A']] mc2 = MyClass (df, 'title', 'descr', [1,2,3,4]) json_data = The second case (after filtering the DF), generates the following error:
previous>attribute: 'weakfor' object has no attribute '__dict__'
How do I resolve this or the other case?
Comments
Post a Comment