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…
Tag: pandas
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,…
Sagemaker lifecycle configuration for installing pandas not working
I am trying to update pandas within a lifecycle configuration, and following the example of AWS I have the next code: Then I attach it to a notebook and when I enter the notebook and open a notebook file, I see that pandas have not been updated. Using !pip show pandas I get: So we can see that I am
Sort pandas DataFrame rows by a list of (index) numbers
I have a pandas DataFrame with 229 rows. I have a list of index numbers ([47, 16, 59, …]) and I want to re-sort the rows of my DataFrame into this order. Details: I ran the DF through a filter (specifically, scipy.cluster.hierarchy.dendrogram, setting get_leaves=True). The return value includes a list o…
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…
Extracting items from xml file and make a dataframe with python
I am trying to extract the following values from an xml file: NAME, Mode,LEVELS,Group,Type and after I want to make data.frame. The problem I having so far is that I cannot get <Name>ALICE</Name> variables and output data.frame format is different than I need. Here is the some post that I used whe…
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…