I have this format of datetime in Python “2022-09-01 08:36:22”, how can I get which weekday of it? I also created this dictionary day_of_week = { 1: “sunday”, 2: “monday”, 3: “tuesday”, 4: “wednesday”, 5: “thursday”, 6: “friday̶…
Tag: pandas
how to Send dataframe as html table with font styling based on text value as a email attachment
I have a dataframe, In that if the value is starting with letter “A” i’m styling it in red color, now i need to send it as html table in mail but when i execute it its coming without that styling, below is the code i tried please help. please check the image for df style enter image descript…
How to change data type in a list of tuples if this type is Timestamp?
I have a list of tuples like this: What I do is: How can I do to change directly the Timestamp type in this list of tuples ? More precisely, if type is pd.Timestamp I would like to change it to np.datetime64. Answer This is an example that should explain what you are missing. The result: [[’12’, 1…
Changing one data frame also changes it’s copy
Couldnt come up with a better title, so here we are. I am running the following code: As far as I understand, I first make a copy of ‘df’ and then I change the copy. What makes me confused is that when I run the second line, the ‘date’ column, becomes the index even in the ‘df…
Pandas .transform() results in NaN values after update to newer version
I have some code that used to function ~3-4 years ago. I’ve upgraded to newer versions of pandas, numpy, python since then and it has broken. I’ve isolated what I believe is the issue, but don’t quite understand why it occurs. Problem: the last line “dc” is a pandas.Series with o…
Replacing values in a pandas dataframe taking row number into account
I have this dataframe taken from an excel file and I want to replace the value column with a string that contains the row number (+1 and with an F so it reference another cell in excel) if the state is “no”. I had no problem replacing some values in the comment column with but I dont know how take
How do I loop through a pandas dataframe, check to see if the data type of each column is a float number, then replace null values with mean?
I am trying to iterate through a pandas Dataframe which has columns with different data types, and replace them with different data types based on their null values. This code did not work as the null values are not replaced in the dataframe. Answer fillna() doesn’t normaly edit your dataframe. you have…
Get index of row where pandas column contains regex
I am checking to see if a pandas column matches a pre-defined regex, using .any() to get the first match if found. However, I need to return the index/row where this match occurred so that I can get the value of another column in that row. I have the below to check where the reg_ex pattern exists in df[‘…
TypeError: argument of type ‘float’ is not iterable. Trying to find rows which doesn’t contain specific words in pandas dataframe
My dataframe looks like this(not exactly, but here is the sample): and I’m trying to find rows only have ‘word’ but without ‘not’ here is my code: and I’m getting this error: I don’t understand why I’m getting this error cause df3[‘WARNSIGN_DTL’] col…
Output sum rounded to the nearest even number using Python
I wish to take the sum of each row and round this value to the closest even number. Data Desired Doing I realize I have to incorporate i+i.mod(2) into this script, however I am not sure how to incorporate. Any suggestion is helpful. Answer here is one way to do it