Skip to content

Tag: python

Apply if else condition in specific pandas column by location

I am trying to apply a condition to a pandas column by location and am not quite sure how. Here is some sample data: The first line works to subtract 1 in the correct locations, however, the remaining cells become NaN. The second line of code does not work – the error is: Answer Instead of selected the first …

How to implement multiprocessing in my python script?

So the thing I’m trying to do is to have multiple cores process some stuff…. I have a py script which basically makes a feature vector for my ML and DL models. Now the thing I’m doing is that I take a txt file, I compare it with a list that I have initialized at runtime. So the code takes

Problem with running shell script echo in Python

I am trying to run this shell script in Python: So in Python3 I do this: So I expect when I run the python code on Linux or Unix I get: But instead I get: What am I doing wrong? Answer There are two problem with this: This is not how you set a variable in a shell. Instead, the

how can I find a date with incorrect Syntax and fix it

I am new to python. I have a dataset I converted it to dataframe. all my dates are objects now. I need to convert them into dates in order to find the age of patients. My dimensions are 3400×14 long. there are date values inside which have incorrect syntax. I cannot find them. is there a way to find them…

Unzip multiple password protected files

I’m a newbie in python. I’m trying to write a simple python script to unzip multiple password protected files in a directory. Passwords are stored in a text file. This is what i have come up with, And below is the content of passwords.txt file, Running above code gives this error, I’m not su…