I have two list such as. First list contains some additional string in the elements but I want to find the match with or without converting it to integer from the second list. output req: Tried: Answer If you only want to compare the number part you have to do some conversion. Start with l2 is now [1, 4]. Now
Tag: dataframe
Matching datetime column in pandas with another datetime column and return index
I have two DataFrames – df1 and df2. Both of them contain a datetime column, say date1 and date2. I want to match each value of date1 column to date2 and store the index in a new column. I am trying the following code: but this line throws out following error: Can only compare identically-labeled series…
Scikit-learn pipeline: Non-finite test scores error / Inconsistent number of samples
I have a dataframe with two columns of texts and only the POS tags (of the same texts), which I want to use for language classification. I am trying to use both features as part of my model. This is what the data looks like: X_train.head() This is what the shape of the data looks like: When I run my
Finding whether there is any overlap between two date periods in DataFrame
I have the following pd.DataFrame that looks like: I want to create a new column received_medidation that states whether or not (boolean) the patient received medication between admission_timestamp and end_period (even if it was for only one second). So, the boolean should state if there is any time between a…
Pandas – Groupby and Standardize
I have tried to tackle this for quite some time, but haven’t been able to get a pythonic way around it by using the built-in groupby and transform methods from pandas. The goal is to group the data by columns ex_date and id, then within the groups identified, standardize the column called ref_value_1 ag…
How to handle Pandas columns where elements are Lists?
I have loaded some JSON API data as a Pandas dataframe, as such, there are some columns that come out as lists. I also have some NaN values. First and foremost I want to replace the NaN with a single word such as ’empty’ but the rest of the data are already in list forms. I want to ultimately crea…
Join two data frames by searching & matching exactly same strings
I have two python dataframes: one of them have a column has a row ‘AC-2’ another data frame includes columns which has a string row ‘AC-20,AC8,AC-15’ First dataset: second dataset: I found: above there is a matching between AC-2 for dataset1 and AC-20 in string for dataset 2 but they a…
Clean Data using Pandas
I have the data in this format, and I want to turn it around in an horizontal shape, and in the same time accumulate the count of one product, when the date and hour data are the same. I put below the new desired data frame. Is this feasible using pandas? Or any other python library? Answer You could groupby+…
DataFrame: how to draw a 3D graph using Index and Columns as x and y, and data as z?
My DataFrame line index and column index store x and y values, while the data values are z values, i.e. f(x, y). Let’s take an example: then f(4, 30) is 160. I would like to make a 3D plot of function f. I don’t really mind if it looks like a 3D histogram or a surface plot – both answers
Create a Nested list from a pandas data frame
I am trying to create a kind of nested list from a pandas data frame. I have this data frame: So I want to create a kind of nested list using the above data frame using ‘id1’ column, and ‘Name1’ and ‘Name2’ columns. For example, if we think about the first row, id1 should b…