I’m trying to get the unique available value for each site. The original pandas dataframe is with three columns: Site Available Capacity A 7 20 A 7 20 A 8 20 B 15 35 B 15 35 C 12 25 C 12 25 C 11 25 and I want to get the unique available of each site. The desired table
Tag: pandas
How to delete duplicates pandas
I need to check if there are some duplicates value in one column of a dataframe using Pandas and, if there is any duplicate, delete the entire row. I need to check just the first column. Example: What i need is: I can delete the ‘object’ duplicates with the following code, but I can’t delete…
pandas change dataset value of a specific row using loc
I’m new to programming, I’m working on a python project using pandas I wanted to change values of each row of a dataset using .loc, but it seems like it won’t work, the idea is to make a row take EOL value if the row is equal to 0, the code doesn’t bring an error, but my dataset is unc…
How to remove duplicates from a dataframe based on the column with string values
I am trying to remove duplicates based on the column item_id from a dataframe df. df : In this df the item_id is as follows: I am using the following function to remove the duplicates. I am unable to remove the duplicates although there rows 0 and 1 have similar item_id. I have some other cases where this fun…
Pandas: Subtract timestamps
I grouped a dataframe test_df2 by frequency ‘B’ (by business day, so each name of the group is the date of that day at 00:00) and am now looping over the groups to calculate timestamp differences and save them in the dict grouped_bins. The data in the original dataframe and the groups looks like t…
Create a new column in a dataframe containing string values from different columns based on values in another column of a dataframe
I would like to add string Null at the end if conversion is 0 and add conversion column value if conversion value is 1 . `I have a below error TypeError: Cannot broadcast np.ndarray with operand of type <class ‘list’> Answer If you have dataframe like this: Then this will create new “p…
Converting UTC time to local in python datetime.time [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations. Closed 1 year ago. Improve this quest…
Calculate the weighted average using groupby in Python
here is the dataframe I’m currently working on : What I’d like to calculate is the average of the variable “avg_lag” weighted by “tot_SKU” in each product_basket for both SMB and CORP groups. This means that, taking CORP as an example, I want to calculate something as: (585…
I’m trying to import CSV file using pandas, But I’m getting Error. (look at pic)
What am I doing wrong?? I’m trying to import a csv file using pandas, i either get an error stating file can’t be found or a unicodeerror message? Answer You should escape your backslashes on Windows – U is interpreted as a unicode character directive in the string. Try:
How to create a pandas dataframe from a nested dictionary with lists of dictionaries?
I have a dictionary like that: I want to construct a dataframe where I can see user1 and user2 as indices, product1, product2 and product3 as columns and values of these products should be values of columns. I tried looking here and found this post Construct pandas DataFrame from items in nested dictionary, b…