hello everyone i have a problem in calculation a data frame in python. i have an equation name is TOC/Total_organic. below is the picture of my equation, code to make new colomns in my data frame, and the result code and result from running the code Answer The problem is that math.log10 cannot handle neither …
Tag: pandas
Create a dataframe based on 3 linked dataframes using a constraint on cumsum
I do have three dataframes like this: that looks as follows and I would like to create another dataframe using these 3 dataframes that looks as follows: Here is the logic for C1: First, one checks the first value in column C1 in df3 which is an a. Second, one checks in df2 where one first finds the letter det…
df.explode() function not working in python
I am facing a weird issue, I have a column name ‘window’ in a data frame and it has a list of values i.e., [3,9,45,78]. I am trying to explode this column using df.explode(‘window’) but this is doing no job. datatype of ‘window’ column is object. I have checked my pandas ve…
Merge dataframes with mirrored values
I have a dataframe which stores measurement points of an circular area. So each point has a Radius_mm and Angle_deg value. As a visual representation of the data, I would now like to create a section through the surface. I.e. I choose one angle and the corresponding angle that lies at 180° to it, including th…
Comparing data between two CSV files to move data to a third CSV file
I have this csv file, file1.csv: Then file2.csv: For every line in file2.csv that has ‘CORP’, ‘STORE’, or ‘NEWS’, I already searched through file1.csv and created a file, such as STOREall.csv, CORPall.csv, and NEWSall.csv. I want OUs, such as ICECREAM, SECURITY, and DELI to…
How to highlight the column in Pandas Dataframe with MultiIndex / advanced indexing by the condition
Could you, please, help me with highlighting the columns in my dataframe with multiindex/advanced indexing? I have the code which forms the Table 1: So, (2022-02-27, ‘Разница в процентах’), (2022-02-26, ‘Разница в процентах’), etc. are columns in this table in python and ‘Источни…
Pandas Dataframe loop to append values to a list for each unique name
I have the following dataframe: I would like to create a list for each unique Name and append the Value values to each list. My expected output is: Any ideas on the most efficient way to do this? thank you! Answer To aggregate as dictionary, you can use: Output:
Select only available rows of a pandas dataframe
Let say I have the following pandas df Now I have another array Clearly, the element ‘x’ is not available in my original df. How can I select rows of df based on select but choose only available rows without any error? i.e. in this case, I want to select only rows corresponding to ‘c’ …
Python Trim Multiple Column Names of a dataframe
I have data frame of 20 columns. All of them have a common text and a serial number. I want to trim the text part and make the name shorter. Below is an example: Expected output: Solution1: Solution2: Solution1 works fine but I have to prepare an old and new column names list. Instead, I want to iterate throu…
How to update a value of a cell of a dataframe using the value of two cells below?
I have the following dataframe (created for an example): Assuming that this is a long dataframe, whenever there is a value of 2 in row B, I need to replace that value with the value that is two cells below that. I tried: But I get: And I need: Does anyone have suggestions for leaving rows that do not equal