I am trying to find a way to take information from one column in a pandas DataFrame and have its unique value be the new column and its score be the value in the newly formed column. I.e. Index Product Test Score 0 A Protection 5 1 A Comfort 6 2 B Protection 6 3 B Comfort 7 And the
Tag: pandas
Converting a time series into start & end dates using Pandas
I’m simply looking for a more intuitive and faster way to get start and end times of uninterrupted time sequences. Here’s a reproducible example as well as my way of doing it for the time being: Resulting dataframe: Any kind of help will be valuable. Answer Another approach is to create a group co…
Extracting Multiple Parameters from a String using Regex or Pandas
I’m working with the following DataFrame Consisting of parameters (bphigh bplow weight) of type stras follows {u’bphigh’: u’120′, u’bplow’: u’70’, u’weight’: u’84.8′} I’d like to extract these parameters and their correspondin…
Excel like vlookup using python pandas with some conditions
I need to perform vlookup on dataframe using python/pandas like in Excel with some conditions. Condition:- I need to create a one new column (DFM) in my 2nd DataFrame using Excel like vlookup. If DFM value is na then print 100% in 2nd Dataframe’s DFM. Like in below result data. In result data DFM column…
How to automatically fill blank column with None in pandas
I have a info.txt file it looks like this: And when I use pandas to read it: the error is: Is there any way to automatically fill the row that not the same column length, the output should looks like: I mean every blank column will be fill with None Answer This works, and should(?) be the same as reading
Search multi-string in pandas column
I have a pandas dataframe which looks like this: Now I want to search col2 on a given condition and select rows accordingly. For example: Answer You can split values and compare with sets by issubset in Series.map:
Dataframe: shifting values over columns
I have a dataframe with some NaN values in my s_x columns. If NaN values exist in them, I want them to be in the last columns. Example: Given values in the s_x columns of [Nan, 1, Nan, 2] I want the values to shift left over the columns to result in [1, 2, NaN, NaN] Example 2: My current
Using a for loop index in .loc to access a rolling slice of a dataframe?
I want to create rolling slices of a master dataframe. I’m trying to measure the difference in outcomes over rolling periods. The master dataframe has 120 years of data and I want to create rolling slices of 10 years of a column(s), i.e slice one goes from year 1 to 10, slice 2 goes from year 2 to 11, e…
Pandas modify column values based on another DataFrame
I am trying to add values to a column based on a couple of conditions. Here is the code example: For each value in the ‘Val’ column of df1, I want to add values from df2, based on the type and whether the original value was positive or negative. The expected output for this example would be altern…
How to plot histogram for below Data Frame
For example this is the DataFrame I want to plot the histogram with X axis showing the Countries and the Y axis showing the amounts on the Y axis, Is this possible. Answer For a dataframe that looks like this: You can plot the graph you want like so: This will produce the following plot: You can check more ab…