So I’m making a text-based game but when I run my code the text isn’t broken up into paragraphs, there is no space between the first print() command and the one right after it. I’ve tried breaking up the text by putting huge spaces between the text in one print command but that is inefficien…
Tuning the hyperparameter with gridsearch results in overfitting
Tuning the hyperparameter with gridsearch results in overfitting. The train error is definitely low, but the test error is high. Can’t you adjust the hyperparameter to lower the test error? before tuning train_error: 0.386055, test_error: 0.674069 -after tuning train_error: 0.070645, test_error: 0.70825…
Flask app on Docker: Max retries exceeded with URL
I’m working on a simple Flask app for which I’m using the default template: I’m just calling a dummy function that return and ‘ok’ response: When I call it directly on my machine with the following code: It works without any issue, but if I run it from the docker image I get the …
Trying to get only the text between two strong tags
I am currently trying to get only the HTML text (a list of names) that is between the first two occurrences of the strong tag. Here is a short example of the HTML I scraped Hers is some quick code that I wrote with the basic logic of counting the number of strong tags occurring. I know after the second
Regular expression for removing all URLs in a string in Python
I want to delete all the URLs in the sentence. Here is my code: But a URL with “http” is still left in the sentence. How can I fix it? Answer One simple fix would be to just replace the pattern https?://S+ with an empty string: This prints: My pattern assumes that whatever non whitespace character…
Which method is the best for starting the bot in discord.py? login() and connect() vs start() vs run()
So, to connect the bot to discord.py, there are several methods: discord.Client().login() + discord.Client().connect() discord.Client().start() discord.Client().run() What is the difference between them and which one is the best for running the bot? Answer I believe the official documentation is very clear: s…
Pandas read_pickle from s3 bucket
I am working on a Jupyter notebook from AWS EMR. I am able to do this: pd.read_csv(“s3:\mypath\xyz.csv’). However, if I try to open a pickle file like this, pd.read_pickle(“s3:\mypath\xyz.pkl”) I am getting this error: However, I can see both xyz.csv and xyz.pkl in the same path! Can a…
Python – Unicode De/Encode
How can I pass all the content from making a db-input(s1), loading it from there (s2) and pass it correctly back-formated to the file? Log: EDIT: I am working on windows. Answer The problem is that you open the file in text mode, but don’t specify the encoding. In that case the system default encoding i…
Python: concatenate pandas multiindex
I need to generate a pd.DataFrame with columns being composed by a list and a Multiindex object, and I need to do it before filling the final dataframe with data. Say the columns are [‘one’, ‘two’] and the multiindex obtained from from_product: I would like to get a list of columns whi…
How to create sparkmagic session automatically (without having to manually interact with widget user-interface)?
I am using sparkmagic to connect Jupyter notebooks to a remote spark cluster via Livy. The way it is now, I need to execute a notebook cell to bring up the %manage_spark user-interface widget, and manually select the language and click “create-session” in order to establish the spark context for t…