I have a python script that returns a pandas dataframe and I want to run the script in a Jupyter notebook and then save the results to a variable.
The data are in a file called data.csv and a shortened version of the dataframe.py file whose results I want to access in my Jupyter notebook is:
# dataframe.py
import pandas as pd
import sys
def return_dataframe(file):
df = pd.read_csv(file)
return df
if __name__ == '__main__':
return_dataframe(sys.argv[1])
I tried running:
data = !python dataframe.py data.csv
in my Jupyter notebook but data
does not contain the dataframe that dataframe.py is supposed to return.