Skip to content

Tag: python

Calculating Euclidean Distance

I have the code below to calculate Euclidean Distance. however, my function does basically nothing. It gives no output and not even an error, it just runs and finishes. Answer Have you called the function? Output: For longer lists, you can also do this faster by summing a generator expression instead: Or you …

Convert SQL Query to MongoDB syntax

I have a big problem with converting SQL queries to Mongo DB for Python. I have a question if you know better methods for transferring SQL queries to Mongo DB queries? I have two queries but I still have big problems with the syntax conversion to Mongo DB. Maybe there is someone here who can help me? Table I …

How to get a value in a column as an index

I assign the eligible index value to A column and then df.ffill() Now I want to use the value of A column as an index and assign the obtained value to the expcted column I try df[‘expected’]=df[‘price’][df[‘A’]] but it doesn’t work. input expected result table Answer …

Loop over regular expressions using Pandas str.extract

I want to extract numeric values from arbitrary strings in a column in my pandas dataframe. Two regexes that shall be looped over the column “watt” using str.extract. The str.extract function shall be applied to all NaN values. On the next iteration, non NaN values (=matches) shall be excluded fro…

Get amount of objects saved in MongoDB using Pymongo

I’m trying to get amount of objects saved in MongoDB with but I’m getting an error I’m using Pymongo 2.0 Answer The find() function for pymongo returns a cursor object (not an array). Pymongo does include a count_documents function. Meaning the code should look like this: Edit: Updated to co…