Skip to content

Tag: pandas

How to use pandas apply to replace iterrows?

I am calculating the sentiment value on every row in the dataset based on news headline. I used iterrows to achieve this: However, the processing time is taking too long (>30 minutes runtime and it is not done yet). I have 16.6k rows in my dataset. This is a small section of the dataset: I have read that i…

Create rolling average pandas

I have a dataset of esports data like this: (done using pd.to_clipboard() I want to create a dataframe that essentially, for each team, every week, creates a rolling X game average of their points scored. (X could be 2, 3, 4, etc). A few notes: This example only shows points, the actual data has about 10 feat…

Pandas dataframe getting specific row and columns

Pandas dataframe has Data in pandas dataframe I need data of first two dates of every fruit name like I have more than 100 fruit names How to write condition for filtering the data? Answer Sort by DATE then groupby FRUIT and keep 2 first rows of each group: