Pandas: cross join with multiple conditions
Consider the following query:
Consider the following query:
Suppose I have the following dataframe where the first column is a facility and the second column is a product produced by the facility.
Say I have the pandas DataFarme looks like this: Name VALUE 0 A 1 1 A 2 2 A 3 3 B 4 4 B 5 5 C 6 6 C 7 7 C 8 8 C 9 9 D 10 I would like to select all the rows with the same name but different … Read more
Below is my DF df = pd.DataFrame({'A': ['a', 'b', 'c', '0'], 'B': ['0xF188-abc-cde', '0xF188-abc-abcde', '0xF188-abc-1234', '0xF188-abc-tu231er']}) Now I want to add NEW column “EXTRACT” which is an extraction of column ‘B’ after second hyphen. Below is the Expected Column. df= pd.DataFrame({'A': ['a', 'b', 'c', '0'], 'B': ["0xF188-abc-cde", '0xF188-abc-abcde', '0xF188-abc-1234', '0xF188-abc-tu231er'], 'Extract':['cde', 'abcde', '1234', 'tu231er']}) Answers: … Read more
Let’s say I have a pandas df like this:
I have 12 columns of ingredients and 12 respective columns of measurements of those ingredients. For some rows the ingredients are specified but the measurements are not i.e. they are NA. I want to set up a condition such that if a certain ingredient entry is not NA and the corresponding entry is NA, set the corresponding measurement entry to 1.
i have the below dataframe
Thank you for your time. I am not an advanced programmer. I am taking 1 programming course. I understand the basics and an okay amount of Python. Please don’t destroy the little confidence I have in programming. I realize the answer may exist but I haven’t found it yet with my searching skills.
What I want to do is look for a specific pattern. 1 letter, a dash, followed by a year and letter like “A-2012A”. After that, the rest of the column’s value can be anything. I want to confirm this first part. And return a true/false value. Is it possible?
Based on the following sample data, the following data frame is built: