Sorting a set of values

From a comment: I want to sort each set. That’s easy. For any set s (or anything else iterable), sorted(s) returns a list of the elements of s in sorted order: Note that sorted is giving you a list, not a set. That’s because the whole point of a set, both in mathematics and in almost every programming language,* is that it’s not ordered: the sets {1, 2} and {2, 1} are … Read more

Flask ImportError: No Module Named Flask

Try deleting the virtualenv you created. Then create a new virtualenv with: Then: Now let’s activate the virtualenv Now you should see (flask) on the left of the command line. Edit: In windows there is no “source” that’s a linux thing, instead execute the activate.bat file, here I do it using Powershell: PS C:\DEV\aProject> & .\Flask\Scripts\activate) Let’s install … Read more

How to change dataframe column names in pyspark?

Option 1. Using selectExpr. data = sqlContext.createDataFrame([(“Alberto”, 2), (“Dakota”, 2)], [“Name”, “askdaosdka”]) data.show() data.printSchema() # Output #+——-+———-+ #| Name|askdaosdka| #+——-+———-+ #|Alberto| 2| #| Dakota| 2| #+——-+———-+ #root # |– Name: string (nullable = true) # |– askdaosdka: long (nullable = true) df = data.selectExpr(“Name as name”, “askdaosdka as age”) df.show() df.printSchema() # Output #+——-+—+ #| name|age| … Read more

How do you call an instance of a class in Python?

You call an instance of a class as in the following: But this will typically give us an error. How can we call the instance as intended, and perhaps get something useful out of it? We have to implement Python special method, __call__! Instantiate the class: Now we can call the class instance: which prints: And … Read more

Can’t open Jupyter notebook with Anaconda

It seems to be a problem with the default installation of Anaconda. So, I removed the pyzmq package, which seems to be the problematic one. This is what I have done: conda uninstall pyzmq (This also removes jupyter related packages!) conda install pyzmq (to reinstall it) conda install jupyter (to reinstall jupyter related packages) Now I can open Jupyter Notebook!