How to fix this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to fix this code?

Below program is working when not saved, after saving, 'Circular Import' error becomes a problem. I want to expand and then save it. Help to debug the code. Note that I am using pydroid3 on Android andd that saving directory is different from local directly. import pandas as pd class PandasAndNumpy: def __init__(self,dataframe): self.data=dataframe self.PandasOnly() def PandasOnly(self): wholedata=self.data print('Printing Whole Data\n%s\n'%wholedata) onecolumn = wholedata['Age'] print('Printing A Single Column\n%s\n'%onecolumn) inp = pd.read_csv('/storage/emulated/0/Folder/CSV/File.csv') PandasAndNumpy(inp)

9th Jul 2021, 12:30 AM
Innocent Salimoni
Innocent Salimoni - avatar
3 Answers
0
Maybe this will help : https://realpython.com/pandas-read-write-files/ Anyway if you want to use classes as a main object to make the sake, please use it properly ; 1- you have only two methods at PandasAndNumpy Class, the __init__ and PandasOnly. My suggestion is to think about the class like an real object that is doing something. Methods describes the thing this object is doing. So make methods related to your need properly. 2- The 'onecolumn' vavriable will not find the column that you want as it is part of an object that is not initialized yet, "class definition is just like a bluepaper, and objects like buildings builded with the same bluepaper". So please create an object and then refer to it along the code. With training, is sure that you'll be better 😀.
9th Jul 2021, 5:05 AM
Ervis Meta
Ervis Meta - avatar
0
Thanks Ervis Meta for your great suggestions. I have learned how methods should be used and how variables should be refererenced in a class method. But my problem still exist even if I remove the class and run a two line code, in this case the first line and the second line from the bottom, just to test the code.
9th Jul 2021, 7:45 AM
Innocent Salimoni
Innocent Salimoni - avatar
0
I have made a sample code for you: Do not copy 😁 https://code.sololearn.com/cXmSF3vbqUTk/?ref=app
9th Jul 2021, 10:25 AM
Ervis Meta
Ervis Meta - avatar