Skip to content

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’ = l…

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, Food…

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 wou…

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&#…

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 wa…