I am building a Streamlit dashboard that will have to read data from a DataFrame. The problem is that I have a local csv and a local Excel file form which I am reading data using pd.read_csv()
.
However, when I share my dashboard url with others, the data will fail to load because they won't have the file locally.
How can I read the contents of a csv and Excel file and turn them into a "hardcoded" pandas DataFrame?
I guess my question is: how should I store and read my data without having local csv and Excel files?
Edit: sorry for no code or MRE, but I literallyu have no idea how to do this. If I had a piece of code, it would simply be a pandas dataframe with sample data in it.
CodePudding user response:
In R I would use dput()
function to show me the code necessary to create a data frame.
For Python I know that print(df.to_dict())
would do something similar to be a "hardcoded" Pandas DF.
So I would do the following:
1: print your df. df.to_dict()
2: copy and paste the necessary code to create the data frame inside your streamlit app. Something similar to this: {'a': {0: 1, 1: 2}, 'b': {0: 3, 1: 3}}
3: "load" the data frames by creating them everytime the application is run. df = pd.DataFrame.from_dict({'a': {0: 1, 1: 2}, 'b': {0: 3, 1: 3}})
PS: note that this solution is not scalable neither would work if your data keeps changing from time to time. If that's the case, you would need to keep printing and pasting your new df to your code every time.