- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Rishikesh Kumar Rishi has Published 1162 Articles
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
Rishikesh Kumar Rishi
841 Views
To sort multiple columns of a Pandas DataFrame, we can use the sort_values() method.StepsCreate a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.Print the input DataFrame, df.Initialize a variable col to sort the column.Print the sorted DataFrame.Example Live Demoimport pandas as pd df = pd.DataFrame( { "x": ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
Rishikesh Kumar Rishi
352 Views
To sort a column in a Pandas DataFrame, we can use the sort_values() method.StepsCreate a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.Print input DataFrame, df.Initialize a variable col to sort the column.Print the sorted DataFrame.Example Live Demoimport pandas as pd df = pd.DataFrame( { "x": [5, 2, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
Rishikesh Kumar Rishi
16K+ Views
We can use apply() function on a column of a DataFrame with lambda expression.StepsCreate a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.Print input DataFrame, df.Override column x with lambda x: x*2 expression using apply() method.Print the modified DataFrame.Example Live Demoimport pandas as pd df = pd.DataFrame( { ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
Rishikesh Kumar Rishi
3K+ Views
To count the frequency of a value in a DataFrame column in Pandas, we can use df.groupby(column name).size() method.StepsCreate a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.Print the input DataFrame, df.Print frequency of column, x.Print frequency of column, y.Print frequency of column, z.Example Live Demoimport pandas as pd df = ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
Rishikesh Kumar Rishi
8K+ Views
To check if a column exists in a Pandas DataFrame, we can take the following Steps −StepsCreate a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.Print the input DataFrame, df.Initialize a col variable with column name.Create a user-defined function check() to check if a column exists in the DataFrame.Call check() method ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
Rishikesh Kumar Rishi
563 Views
To replace NaN values by zeroes or other values in a column of a Pandas DataFrame, we can use df.fillna() method.StepsCreate a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.Print the input DataFrame, df.Use df.fillna(0) to replace NaN in DataFrame with value 0.Similarly use df.fillna(5) and df.fillna(7) to replace NaN in ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
Rishikesh Kumar Rishi
753 Views
To replace NaN values by zeroes or other values in a column of Pandas Series, we can use s.fillna() method.StepsCreate a one-dimensional ndarray with axis labels (including time series).Print the input series.Use s.fillna(0) to replace NaN in the series with value 0.Similarly, use s.fillna(5) and s.fillna(7) to replace NaN in ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
Rishikesh Kumar Rishi
2K+ Views
To create a DataFrame with some index, we can pass a list of values and assign them into index in DataFrame Class.StepsCreate a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.Put a list of indices in the index of DataFrame class.Print the DataFrame with the customized index.Example Live Demoimport pandas as pd ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
Rishikesh Kumar Rishi
781 Views
To check if any value is NaN in a Pandas DataFrame, we can use isnull().values.any() method.StepsMake a series, s, one-dimensional ndarray with axis labels (including time series).Print the series, s.Check whether NaN is present or not.Create a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.Print the input DataFrame.Check whether NaN is ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
Rishikesh Kumar Rishi
272 Views
To reset hierarchical index in Pandas, we can use reset_index() method.StepsCreate a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.Print the input DataFrame.Use groupby to get different levels of a hierarchical index and count it.Print multi-hierarchical index DataFrame.Reset the multi-hierarchical index DataFrame, using df.reset_index().Print the new updated DataFrame.Example Live Demoimport pandas as ... Read More