Top Rarely Used Pandas Function In 2023 One Should Know
Top rarely used Pandas functions in 2023 that one should know:
- shift(): This function shifts the element to a desired location as per the desired number of periods we enter as a parameter. This function can work on both columns and also on rows.
- query(): This function is used to filter a DataFrame based on a given condition. This function can be used to filter rows or columns based on a variety of criteria.
- replace(): This function is used to replace a specific value with another value in a DataFrame. This function can be used to replace missing values, invalid values, or values that need to be changed for some reason.
- drop_duplicates(): This function is used to drop duplicate rows from a DataFrame. This function can be used to clean up a DataFrame and remove any duplicate rows.
- info(): This function provides information about a DataFrame, such as the number of rows, columns, data types, and memory usage. This function can be used to get a quick overview of a DataFrame.
These are just a few of the many rarely used Pandas functions that can be useful for data analysis. By learning these functions, you can become a more proficient Pandas user and be able to perform more complex data analysis tasks.
Here are some examples of how these functions can be used:
- To shift the temperature column in the weather dataset by one day, you would use the following code:
df['temperature'] = df['temperature'].shift(1)
- To filter the movies DataFrame to only include movies with a rating greater than 8.0, you would use the following code:
df = df[df['rating'] > 8.0]
- To replace all missing values in the height column with the average height, you would use the following code:
df['height'].fillna(df['height'].mean(), inplace=True)
- To drop all duplicate rows from the students DataFrame, you would use the following code:
df = df.drop_duplicates()
- To get information about the titanic DataFrame, you would use the following code:
df.info()