I have 3 dataframes (df1, df2 & df3), the main one (df1) and two additional ones which contain 1 column amongst others that I want to bring over to the main dataframe. Sample dfs: df1 df2 and df3 I am using the following code: Then for the two empty strings for the “Objective” column I want to…
Tag: pandas
pandas groupby() and pivot_table() .style.format() from float to currency for specific column
I’ve got a Pandas DataFrame looking like this: yields this result: now doing the same groupby but with an added aggregate like count results in: What I would like to have is a result like this: I tried variations of these: but they only reformatted the sum column Answer What you have is a column MultiIn…
Save Dataframe changes to the same xlsx file using pandas (append)
Trying to save changes to the same xlsx file without overwriting it, What I use to read the file This has overwritten my file According to Pandas team the following could be used https://github.com/pandas-dev/pandas/blob/main/pandas/io/excel/_base.py#L800-L814 If someone could guide me through this I would be…
How to plot colors based on cell values on a timestamp
I have a data which contains 16 columns, from which 1 column is “Time” column and other 15 columns are columns that represent colors. Data looks like this: What I need is to have a plot in which at every timestamp represent these 15 colors. The output should look like this: Any idea how to do this…
Can’t figure out why pandas.concat is creating extra column when concatenating two frames
I’ve been trying to concatenate two sheets while preserving the original indices of both dataframes. However, upon concatenation I can’t seem to get the result to output the way I expect or want. If I use ignore_index = True The old indices are replaced by an index that encompasses both sheets tot…
Map different column values with website context
I have a dataframe like this: What I want is to map the columns values with their description from this site https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/system-stored-procedures-transact-sql?view=sql-server-ver15 So for example this value EXEC sp_droplogin can be mapped…
Comparing Two dataframes of pandas on the basis of condition of two columns
I have two dataframe in which columns are different, And I need to search and the map the data in new file. I am sharing the dataframes and also desired output DF1 DF2 Now I need to a output from above two dataframes. Conditions Need to search Ref.Y in STR2, if available then pick the “Type” for o…
How to delete empty spaces from pandas DataFrame rows until first populated field?
Lets say I imported a really messy data from a PFD and I´m cleaning it. I have something like this: Name Type Date other1 other2 other3 Name1 ” ” Type1 ” Date1 Name2 ” ” ” Type2 Date2 Name3 ” ” Type3 Date3 ” Name4 ” Type4 ” ” Date4 Name5 …
Python Dataframe find closest matching value with a tolerance
I have a data frame consisting of lists as elements. I want to find the closest matching values within a percentage of a given value. My code: Present solution: Expected solution: Answer Idea is get difference with val and then replace to missing values if not match tolerance, last get np.nanargmin which rais…
Transforming data using Python Pandas (or M) in Power Query for PowerBi
I have some data about projects I would like to transform in a way that makes it easier to analyse with PowerBi. The data looks like this: Project Number Project Name Planned Start Date SM1 SM2 SM3 10000 A Apr-21 10 20 30 10001 B Jun-21 40 50 60 10002 C Sep-22 70 80 90 The so called ‘SavingMonths’…