Skip to content
Advertisement

Tag: pandas

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 N

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?

Spline interpolation on dataframes by row

I have the following data frame: I am trying to apply a spline interpolation on each row to get the values for 2017 and 2018 using the following code: However, I get the following error: ValueError: Index column must be numeric or datetime type when using spline method other than linear. Try setting a numeric or datetime index column before

Change pandas dataframe content in a function

I’m writing a class that does one hot encoding, but it doesn’t work as I expected. On my main code I have this: The class method is the following: Now, with print(data.columns) I can see that the method works correctly, but when train_x_categorical.head() runs I can’t see the effect of the method applyOneHotEncoding. I don’t understand why this is happening

Advertisement