Summary
I am trying to run to my Streamlit app a code that was converted from a Jupyter notebook to python. I am fairly confident that the code was converted successfully as I have used code previous converted from a Jupyter notebook and had no issues.
Steps to reproduce
add code here
import pandas as pd
import re
df1 = pd.read_excel("C:\\Users\\avida\\freeweibo-09-15-2022.xlsx")
#df.index.names = ['row_id']
df2 = df1[['User_name', 'time_created', 'OriginalPostLink', 'HotTerm', 'content']]
df2 = df2.dropna() # If column value is empty drop the entire row
df2['orig_freeweibo_row_id'] = df2.index
weibo_id_list = []
for ind in df2.index:
row_content = df2['OriginalPostLink'][ind]
weibo_id = re.findall(r'\d+', str(row_content)) or ["Error"]
# print(weibo_id[0])
weibo_id_list.append(weibo_id[0])
#print(weibo_id_list)
df2['weibo_ids'] = weibo_id_list
# Dropping rows that contain ['0'] as a weibo id
###df2 = df2[df2["weibo_ids"].str.contains("0") == False]
# Remove rows where content is 'NaN'
# df2.head()
print("Number of rows in original data: ", len(df1))
print("Number of rows after removing empty rows in columns:", len(df2))
print("Number rows removed:", len(df1) - len(df2))
print("Range of the index:", len(df2[df2['content'] != 2].index))
# df2['content'] != 2 subsets the df2, and len(df2.index) returns the length of the index.
# https://stackoverflow.com/questions/47539511/how-to-get-range-of-index-of-pandas-dataframe
df2.head()
If applicable, please provide the steps we should take to reproduce the error or specified behavior.
Explain what you expect to happen when you run the code above.
The expected behavior is for the code to print number of rows in original data, number of rows after removing empty rows in columns, number of rows removed and range of the index. In addition there is a generic table that is usually displayed in streamlit that displays the data.
Explain the undesired behavior or error you see when you run the code above.
If you’re seeing an error message, share the full contents of the error message here.
I received the error when running the code streamlit run filename.py
Usage: streamlit run [OPTIONS] TARGET [ARGS]…
Try ‘streamlit run --help’ for help.
Error: Streamlit requires raw Python (.py) files, but the provided file has no extension.
For more information, please see https://docs.streamlit.io
Streamlit version: 1.15.1
- Python version: 3.9.15
- Using Conda
- OS version: Windows 10
- Browser version: Chrome
Requirements file
Using Conda? PipEnv? PyEnv? Pex? Share the contents of your requirements file here.
Not sure what a requirements file is? Check out this doc and add a requirements file to your app.
Links
- Link to your GitHub repo:
- Link to your deployed app:
Additional information
If needed, add any other context about the problem here.