Skip to content
Advertisement

Tag: python

Discord.py how do I send a DM to anyone I want through a command

Someone asked me to make a bot for him that sends a DM to anyone he specifies through a command, like *send_dm @Jess#6461 hello. I’ve searched alot and I came across this code: but then I got the error: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: ‘Bot’ object has no attribute ‘send_message’ I want to type for example : *send_dm @Jess#6461

pytest requires Python ‘>=3.5’ but the running Python is 2.7.10

I’m trying to install pytest using pip but running into this error: Pretty sure pytest is compatible with python 2. Any reason why I am not able to install it on my machine? As you can see in the error, I am running python 2.7.10 and do not have issue installing other packages. Answer Quoting the changelog: The 4.6.X series

Sklearn PCA explained variance and explained variance ratio difference

I’m trying to get the variances from the eigen vectors. What is the difference between explained_variance_ratio_ and explained_variance_ in PCA? Answer The percentage of the explained variance is: The variance i.e. the eigenvalues of the covariance matrix is: Formula: explained_variance_ratio_ = explained_variance_ / np.sum(explained_variance_) Example: Also based on the above formula: 7.93954312 / (7.93954312+ 0.06045688) = 0.99244289 From the documentation:

Fast way to cyclically wrap values in pandas dataframe

In words: I have a data frame that consists of values over a day, for multiple days per Userid. I’d like to shift all of certain people’s data by 1 period, so that the first value in their first column is a nan, and then everything is cyclically offset, with the last value truncated or lost to space and time,

Advertisement