I’m trying to get from a to b. I got a Pandas data frame similar to the a below. I realize I’ve backed myself into a corner by computing sums in a flat file. I’m new to Python. I guess I should create the sums when I’m done pivoting? What I am stuck in is this wrong b struggle, I
Tag: pandas
Obtain all Pairs of Strings which are Contained in Each Other [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 months ago. Improve this question I have a list of strings and I want to extract all pairs of strings such that the first str…
How to replace images path in xlsx with original images using python [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 months ago. Improve this question I have an excel file where one field has an image path. below is the samp…
How can I check the value that exists for the earliest date?
df: country year index Turkiye 1992 NaN Spain 1992 NaN US 1992 1 Turkiye 1993 1 Spain 1993 1 US 1993 0 Turkiye 1994 1 France 1994 0 Italy 1994 NaN Turkiye 1995 0 Here, for example, in 1992 Turkiye and Spain are NaNs but the index exists for the US. So I am only interested in the earliest date
How do I add the counts of two rows where the values in the columns are swapped with respect of the other?
I have a Dataframe as follows: I have to count how many pairs of Sources and Targets there are. (1,0) and (0,1) will be treated as duplicate, hence the count will be 2. I need to do it several times as I have 79 nodes in total. Any help will be much appreciated. Answer To count pairs regardless of their
Json to CSV file conversion using python
I have a sample JSON file like this i need to take only specific key and values from the json file and convert it into a CSV file Code: Ref:Extracting Specific Keys/Values From A Messed-Up JSON File (Python) When I’m passing 2 values through the extract(), getting NaN in between result I need to get an …
Passing multiple dataframes as arguments to a function
I have been scratching my head since morning on how to tackle this problem. I need to pass multiple columns from multiple dataframes to a function as arguments. Example : Df1 A B C 1 11 111,333 2 22 222 3 33 nan Df2 D E a 111 b 333 Now, I want all the rows from Df2(col E) which
Merge lists in a dataframe column if they share a common value
What I need: I have a dataframe where the elements of a column are lists. There are no duplications of elements in a list. For example, a dataframe like the following: I would like to obtain a dataframe where, if at least a number contained in a list at row i is also contained in a list at row j,
Populating Country column from international phone numbers
I have a dataframe with several data including the column phone. I would like to create a column name country, based on the phone numbers. The phone numbers are in the format +country_code_phonenumber, i.e.,for several countries. Example What is the best way to do this with the library phonenumbers? Or is the…
Two constraints setting together in optimization problem
I am working on an optimization problem, and facing difficulty setting up two constraints together in Python. Hereunder, I am simplifying my problem by calculation of area and volume. Only length can be changed, other parameters should remain the same. Constraint 1: Maximum area should be 40000m2 Constraint 2…