Skip to content
Advertisement

Tag: python

How to run a Python module from Linux console?

I am a beginner in Linux and I am trying to do something very basic (yet it does not seem to work). I have installed a python3 package. I wish to run this Python package on a specific folder from my linux machine. The idea is that this package should restructure all my files in a specific format (this is

If statement not executing. Python

I am still new to programming and I wanted to do a simple calculator in python. However, I could only reach this point of my code: Not sure why my if statement is not executing after all the correct inputs from the user. I mostly focused on the error handling part and after everything going well, the if statement is

Plotting values above a threshold in Python

Having issues with plotting values above a set threshold using a pandas dataframe. I have a dataframe that has 21453 rows and 20 columns, and one of the columns is just 1 and 0 values. I’m trying to plot this column using the following code: But get the following errors: Any suggestions on how to fix this? Answer The error

Fill up column based on condition goes wrong

I am trying to fill a column based on condition but something goes wrong. So I am expecting if it is not 2017 there should be a no. But yet the years 2019 and 2020 also get filled up with yes. Does anyone know what went wrong? Answer Use Series.between instead & for bitwise AND, for chain by bitwise OR

Switch pandas data frame to dictionary

I have a pandas data frame of the following shape: MNK Monkey CT Cat GNNPG Guinnea Pig And I want to switch it into such dictionary: {‘MNK’:’Monkey’,’CT’:’Cat’,’GNNPG’:’Guinnea Pig’} Is there a way of doing such transformation (without iterating on rows) ? Answer Calling your DataFrame as df and columns code and `animal, you can declare a dictionary iterating over it.

Discord.py – How to set slash command parameter’s name and description

I’m trying to make discord bot using python discord.py module, and I wanna add slash command with member parameter using CommandTree. I added parameter but it does not have it’s own parameter name(displays as it’s variable name) and description. How can I add its name and description? Answer You can use the app_commands.describe and the app_commands.rename decorators to do this:

Advertisement