psycopg2.OperationalError: could not connect to server: Connection refused Is the server running on host “45.32.1XX.2XX” and accepting TCP/IP connections on port 5432? Here,I’ve open my sockets. I googled that I should modify this pg_hba.conf,but in my postgresqlroot files, I didn’t fi…
In Pandas, how to delete rows from a Data Frame based on another Data Frame?
I have 2 Data Frames, one named USERS and another named EXCLUDE. Both of them have a field named “email”. Basically, I want to remove every row in USERS that has an email contained in EXCLUDE. How can I do it? Answer You can use boolean indexing and condition with isin, inverting boolean Series is…
Python regex to remove punctuation except from URLs and decimal numbers
People, I need a regex to remove punctuation from a string, but keep the accents and URLs. I also have to keep the mentions and hashtags from that string. I tried with the code below but unfortunately, it replaces the characters with accents but I want to keep the accents. The output for the following text &#…
How to dump a dictionary into an .xlsx file with proper column alignment?
I have a dictionary with 2000 items which looks like this: Given that I want to write it to an .xlsx file, I use this code (taken from here): This produces an .xlsx file with the following alignment: However, this is the alignment I am after: What should I change in the script to achieve this? Answer This is …
Google Foobar Challenge 3 – Find the Access Codes
Find the Access Codes Write a function answer(l) that takes a list of positive integers l and counts the number of “lucky triples” of (lst[i], lst[j], lst[k]) where i < j < k. The length of l is between 2 and 2000 inclusive. The elements of l are between 1 and 999999 inclusive. The answer fi…
matplotlib histogram: how to display the count over the bar?
With matplotlib’s hist function, how can one make it display the count for each bin over the bar? For example, How can we make the count in each bin display over its bar? Answer it seems hist can’t do this,you can write some like :
How to run Spark code in Airflow?
Hello people of the Earth! I’m using Airflow to schedule and run Spark tasks. All I found by this time is python DAGs that Airflow can manage. DAG example: The problem is I’m not good in Python code and have some tasks written in Java. My question is how to run Spark Java jar in python DAG? Or may…
pandas, apply with args which are dataframe row entries
I have a pandas dataframe ‘df’ with two columns ‘A’ and ‘B’, I have a function with two arguments and I would like to apply it row-by-row to df using the ‘apply’ function but I get the error whats happening here, it seems it takes df[‘A’] as the whol…
implement mat2gray in Opencv with Python
I have the same problem with him: Scaling a matrix in OpenCV I got the same problem with him, I have a colored picture, I used matlab to read the picture: Input = imread(‘input1.jpg’);, and the format of the picture is 612x612x3 uint8, I print the 5x5x1 pixel in the picture as below:Input(1:5,1:5,…
ValueError: Could not find a default download directory of nltk
I have problem on import nltk. I configured apache and run some sample python code, it worked well on the browser. The URL is : /localhost/cgi-bin/test.py. When I import the nltk in test.py its not running. The execution not continue after the “import nltk” line.And it gives me that error ValueErr…