I am looking to compare values of columns in two different datasets and create a column with the results that have matched. DF1: DF2 = Expected Result DF1: I can see the matches using the following code: And i can return a 1/0 with the following: However, i cannot seem to merge them both Answer Output:
Tag: pandas
Pandas look for substring then write in another
So I’m trying to look down a specific column of my csv file for a partial string. If that meets a certain condition, it’ll write something else in a different column. For example: The “Percentage” column will always have the same format of “Ninety Five Percent” that is numb…
Create New Columns Using Multiple Conditions And Time Difference
I have the following dataframe with a tricky problem: I have to make 4 columns (0-90 days, 91-180 days, 181-270 days, 271-360 days) based on the following conditions: Desired output: What would be the smartest way of doing it? Any suggestions would be appreciated. Thanks! Answer You can write a custom functio…
: aggregate() missing 1 required positional argument: ‘func_or_funcs’
I try to aggregate per ptid based on the diag_date, and calculate max, min and visit counts based on the diag_date: However, when I do the above (following all rules for agg) does not seem to work as I get the following error: Any ideas, are greatly appreciated! Answer To answer my questions, after getting va…
Replace Values of Multiple Columns in Pandas Dataframe More Efficiently
I have a DataFrame, df, where I would like to replace several values user1 user2 user3 apple yoo apple mango ram mango Instead of doing to get the final DataFrame of user1 user2 user3 0 2 0 1 3 1 Is there any way I make the code above more efficient such that I can change the values of apple,
how to print first name, last name and birthday in python?
I’m trying to print first name, last name and birthday, so how i could do it? Here’s my code: Output should be like this: last_name first_name birthday Cawthorn David 1995-08-01 Answer First add parse_dates to read_csv for datetimes: Then if need filter by minimal birthday and columns in list use …
Problems Removing Duplicated Words from Pandas Row
I am working on an NLP assignment and having some problems removing duplicated strings from a pandas column. The data I am using is tagged, so some of the rows of data were repeated because the same comment could have multiple tags. So what I did was group the data by ID and Comment and aggregated based on ta…
Converting a Dictionary to DataFrame in Python
I have a dictionary of a static structure: I will need to record data a few extra keys deep to the same depth, so somewhat uniform. Example Dictionary: I want a DataFrame of this structure: Example Desired DataFrame: Where all Child Values are either a list object of strings or a string object. From researchi…
calculate number of non-missing counts in specific columns
I have a data like below: I want to get count of non-missing based on F and L: I tried below’s code but got wrong result since it considered F and L separate instead of based on their suffix: Any idea? Answer
Concat multiple small DataFrames as one big DataFrame
I’m trying to make a large DataFrame from a bunch of smaller DF. so I’ve look at multiple sites a nd they all mention to use the pd.concat() method and create an empty DataFrame. I did, however when I print inside my for loop I still get data as if it was still sectioned by individual DataFrame, a…