Advertisements
Advertisements
प्रश्न
Explain the concept of GROUP BY with help on an example.
कोड लेखन
स्पष्ट करा
Advertisements
उत्तर
GROUP BY is used to group data based on one or more columns and perform calculations like sum, count, average, minimum, and maximum on each group.
import pandas as pd
data = {'Department':['IT','HR','IT','HR'],
'Salary':[50000,40000,60000,45000]}
df = pd.DataFrame(data)
df.groupby('Department')['Salary'].sum()
Output:
| Department | |
| HR | 85000 |
| IT | 110000 |
| Name | Salary, dtype: int64 |
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
