Reputation: 171
I am trying to import a dataframe from funcs.py file to data.ipynb file, both are in the same directory
funcs.py
df_course = pd.read_sql('SELECT COURSEID, COURSENAME FROM COURSE', con=conn)
here conn is the pyodbc connection , it is working fine as i am able to view dataframe in funcs.py
error
When i tried to import df_course in data.ipynb it is giving me error, i am doing like this
import funcs.df_course as df_course
but it is giving me error that cannot import df_course from funcs
Please help me in this problem
Upvotes: 2
Views: 432
Reputation: 156
Instead Of import funcs.df_course as df_course
;
Use This:- from funcs import df_course as df_course
For The Name That You Want, as df_course
is not necessary, but if u want to import it as df
or something, then you can use df_course
..
Upvotes: 0
Reputation: 174
I recommend you to read this: https://jupyter.readthedocs.io/en/latest/contributing/docs-contributions/getting-started.html?highlight=ipynb#edit-the-documentation-source-file
honestly, It's difficult to understand what you want from Jupyter notebook. Did you use Jupyter? If yes, you have a file with extension .ipynb. but It's your code, it isn't your dataframe...
Upvotes: 0
Reputation: 120489
Simply use:
from funcs import df_course
because funcs
is not a package, a directory that contains an __init__.py
file.
Upvotes: 3
Reputation: 33
Try this:
import sys
function_path = r'C:\Users\hogsione\jupyter' # Path of funcs.py file
sys.path.insert(1, function_path)
# Now import df_course
from funcs import df_course
Upvotes: 1