Skip to content

Tag: pandas

Creating new columns from the values of another column

I have a column in a dataframe with different strings. What I want to do is to create new columns, IP Address and MAC Address with the corresponding values from the column above. So that the expected output looks like this: The problem is, that I cannot deal with the rows that does not contain IP and MAC. I t…

Can’t get substring from strings. Help needed

I have a column that contains string like Expected Output: What I need is to get the substring (GDNDL380F4) after Name= to column Name and substring (FTT-87) after Type= to column Type. I tried different approaches with str.extract, find and re.find but for some reason I get wrong result (nan or an empty arra…

Taking the min value of N last days

I have this data frame: I want to show the min value of n last days (say, n = 4), using Date column, excluding the value of current day. A similar solution has provided by jezrael. (That one calculates the mean, and not min.) Expected result: Answer Use similar solution like @Chris with custom lambda function…

Coloring pivot table pandas dataframe

I have a pivot table created using pandas which looks like below: I want to apply color for the entire column based on account name starts with. Ex: If account name starts with “AA” color=yellow, if starts with “AB” then color = red How can I do that in python and save it into excel fi…

Pandas – merge multiple time columns and fill values

I have a dataframe (df): I need to merge the time columns, sort them, then fill the missing values in a “downwards” manner. The expected output is like so: Answer Use wide_to_long with some preprocessing – rename time column and convert index to column, then sorting by DataFrame.sort_values,…

decompose() for time series: ValueError: You must specify a period or x must be a pandas object with a DatetimeIndex with a freq not set to None

I have some problems executing an additive model right. I have the following data frame: And when I run this code: I got that message: ValueError: You must specify a period or x must be a pandas object with a >DatetimeIndex with a freq not set to None What should I do in order to get that example: The scre…

Connecting means in seaborn box plot

I want to connect box plot means. I can do the basic part but cannot connect box plot means and box plots offset from x axis. similar post but not connecting means Python: seaborn pointplot and boxplot in one plot but shifted on the x-axis As we can see the sns.line plot does not follow the means and box plot…