Data Science ppt on dataframe operations.pptx

CoolGamer16 16 views 6 slides May 27, 2024
Slide 1
Slide 1 of 6
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6

About This Presentation

ppt on dataframe operations


Slide Content

Dataframe operations By: Harsh, kartik , ansh , rohit

aggregation Aggregation functions allow you to summarize the data in a DataFrame by calculating a single value for each column. The most common aggregation functions are: sum(), mean(), median(), mode(), std(), and var(). To use an aggregation function, you can pass it to the agg () method of a DataFrame . For example, to calculate the mean of each column in a DataFrame , you would use the following code: import pandas as pd df = pd.DataFrame ({'A': [1, 2, 3], 'B': [4, 5, 6]}) df.agg (['mean'])

Group by The groupby () method allows you to group the rows in a DataFrame by one or more columns. This can be useful for performing aggregation operations on specific groups of data. For example, to calculate the mean of each column in a DataFrame , grouped by the "A" column, you would use the following code: import pandas as pd df = pd.DataFrame ({'A': [1, 2, 3], 'B': [4, 5, 6]}) df.groupby ('A'). agg (['mean'])

sorting The sort_values () method allows you to sort the rows in a DataFrame by one or more columns. You can specify whether to sort in ascending or descending order by passing the ascending parameter to the sort_values () method. For example, to sort the rows in a DataFrame by the "A" column in ascending order, you would use the following code import pandas as pd df = pd.DataFrame ({'A': [1, 2, 3], 'B': [4, 5, 6]}) df.sort_values ('A', ascending=True)

Renaming index The set_index () method allows you to rename the index of a DataFrame . You can pass a column name or a list of column names to the set_index () method. For example, to rename the index of a DataFrame to the "A" column, you would use the following code: import pandas as pd df = pd.DataFrame ({'A': [1, 2, 3], 'B': [4, 5, 6]}) df.set_index ('A')

pivoting The pivot_table () method allows you to reshape a DataFrame by pivoting the rows and columns. This can be useful for creating summary tables and cross-tabulations. For example, to create a summary table of the mean of each column in a DataFrame , grouped by the "A" column, you would use the following code import pandas as pd df = pd.DataFrame ({'A': [1, 2, 3], 'B': [4, 5, 6]}) df.pivot_table (values='B', index='A', aggfunc ='mean')
Tags