Using python, I want to merge on multiple variables; A, B, C, but when realization a-b-c in one dataset is missing, use the finer combination that the observation has (like b-c). Example: Suppose I have a dataset (df1) containing person’s characteristics (gender, married, city). And another dataset (df2…
Tag: pandas
How do I use sum and count functions together on different columns in my data frame function?
My data frame is the following: My current function is: It outputs the following: What is the best way to modify my function to give me the sum of the price as well? Example: I have looked at the .agg method but I’m lacking examples that use different columns. (I’m also not sure if that’s th…
Grouping column values in pandas and making other column values into a list
I have a pandas dataframe: I would like to change it to a dataframe like this: Is there a simple way to achieve this? Answer You need custom lambda function for lists only if length is greater like 1: because if aggregate by list get also one element lists:
Pandas save to_csv format not tabbing spaces
I want to write some data using a panda frame to a .dat file. Saving isnt an issue its formating. I’ve used sep = ‘t’ but it only some times places a tab between data. My code looks like this: the resulting data: Why? and how do I fix this? Im also trying to set up my code so the
How to multiply all numerical columns of a dataframe by a one-dimensional array?
I have a dataframe df of shape r x c, with 1 text column (with non-unique values) and the other columns all floats. I then have an array mult of size r. I would like each numerical column of the dataframe to be multiplied by the corresponding item of the array. Ie the desired output is that value_1[0] should …
Splitting Dataframe into different group by product
I am trying to split my Dataframe such that each Dataframe is for a product. Given below is how my Dataframe looks like: Expected output: Dataframe for prod_a Dataframe for prod_b Dataframe for prod_c Answer I suggest here create dictionary of DataFrames in dictionary comprehension: Variables from strings are…
SettingWithCopyWarning, how to stop it?
I have this code, it’s working for the first 9 itterations and then I get the SettingWithCopyWarning and it doesnt continue on, what can I do? So I have this now, but it still only runs through the first 10 lines of data! Something to do with the first for loop I think! (I know it’s still a for lo…
How to extract a string from one column and save it in a new column in pandas dataframe?
This is my dataframe: I want to extract from refactorings column : Add parameter which is the type and com.github.pockethub.android.core.issue.IssueFilter which is after from class and put them into a new column and then delete refactorings column. The Wanted datframe is: this is my code: It did not extract c…
Passing datetime64[ns] from pandas’ data frame as an argument to a function
I’m trying to create an additional column in a data frame to show the number of network days (excluding custom holidays) between two dates. I’m using a function to which I’m trying to pass dates from df’s columns as arguments, but I can’t make it work. Below is my code (I’m…
Can I avoid that the join column of the right data frame in a pandas merge appears in the output?
I am merging two data frames with pandas. I would like to avoid that, when joining, the output includes the join column of the right table. Example: df.columns will give the output Index([‘Name’, ‘Age’, ‘Name_child’, ‘Toy’], dtype=’object’). Is there…