0
votes

I am trying to create 2 python classes, class CsvtoDataFrame for moving data from csv to DataFrame. and class DataFrametoDB from Dataframe to database. When I am trying to return the dataframe from CsvtoDataFrame and print it. It says "<main.CsvtoDataFrame object at 0x00981890>" How can I see the data of the dataframe outside the CsvtoDataFrame . I need help in this. Please!

import pandas as pd

class CsvtoDataFrame: global pd_sales def init(self,FileName): self.FileName = FileName pd_sales=pd.read_csv(FileName) #print(pd_sales) def ReturnFile(self): return pd_sales

class DataFrametoDB: def init(self,obj): self.pd_sales=obj.pd_sales print(self.pd_sales) df=CsvtoDataFrame('test.csv') print(df)enter image description here

1

1 Answers

0
votes

In order to return pd_sales, you may need to create another function, insteading of doing in def init(self, FileName).

import pandas as pd

class CsvtoDataFrame: 
    global pd_sales 

    def __init__(self,File): 
        self.FileName = File
        
        #print(pd_sales) 
    def readcvs(self):
        pd_sales=pd.read_csv(self.FileName)
        return pd_sales;


class DataFrametoDB: 
    def __init__(self,obj): 
        self.pd_sales=obj.pd_sales 
        print(self.pd_sales)


df=CsvtoDataFrame('test.csv')
df2=df.readcvs()
print(df2)