Skip to content
Advertisement

Tag: pandas

Pandas .loc[].index

What is the most efficient way (using the least amount of lines possible) to locate and drop multiple strings in a specified column? Information regarding the .tsv dataset that may help: ‘tconst’ = movie ID ‘region’ = region in which the movie was released in ‘language’ = language of movie Here is what I have right now: I am trying

Pandas find most bought item given ClientID ItemID ItemQuantity

Among the columns of my DataFrame I have ClientID CartID FoodID Quantity, I would like to find what is the food that the client has bought the most. I tried this: But got a completely wrong output: EDIT: I also tried but this results in a pair (ClientID, Quantity of the most bought food), I need (Client, FoodID) Answer First

How to choose only the “male” attribute from a newly compiled dataframe?

I am working with the following dataframe which I created from a much larger csv file with additional information in columns not needed: df_avg_tot_purch = df_purchase_data.groupby([“SN”, “Gender”])[“Price”].agg(lambda x: x.unique().mean()) df_avg_tot_purch.head() This code results in the following: SN Gender Adairialis76 Male 2.28 Adastirin33 Female 4.48 Aeda94 Male 4.91 Aela59 Male 4.32 Aelaria33 Male 1.79 Name: Price, dtype: float64 I now need

Pandas add missing weeks from range to dataframe

I am computing a DataFrame with weekly amounts and now I need to fill it with missing weeks from a provided date range. This is how I’m generating the dataframe with the weekly amounts: Which outputs: If a date range is given as start=’2020-08-30′ and end=’2020-10-30′, then I would expect the following dataframe: So far, I have managed to just

Applying lambda to whole dataframe with if condition

I have a df that looks like this: I want to calculate the mean of the columns where A>0 so that my df would look like this: I use: But get: TypeError: ‘float’ object is not subscriptable I also tried But get: KeyError: False Which is produced by the x[‘A’]>0 mask. And: I couldn’t find a solution how can I

Difference of letting DataFrame’s column

I don’t know the difference of two ways that I let columns of DataFrame. the codes are here: when I printed A[‘ftr3’] to see elements of ftr3 of A, there was no problem. But when I printed B[‘ftr3’], the problem occured: Moreover, the reason I’m confused with this result was that print(A) and print(B) prints exactly same results. the results

Advertisement