Pandas is one of the most popular packages in Python. It is widely used for data manipulation, data cleaning and wrangling. Panda’s package comes up with multiple feature-rich functions and options which could be overwhelming. This pandas cheat sheet might be a handy tool in such instances where one could quickly brush up the basics of Pandas.
Contributed by: Lalit Pavan
- Series and Data frame are two prominent data structures of Pandas library.
- Series is a one-dimensional labeled array capable of holding any data type
- Data Frame is a 2-dimensional labeled data structure with columns of potentially different types. You can think of it like a spreadsheet or SQL table.
Creating Data Frame:
Below we are creating a data frame from a dictionary.
To retrieve basic information from a Data Frame:
To use a Column as Index:
To Sort the Data Frame by Index/Column:
To drop a column from a Data Frame:
To select rows/columns of a data frame based on index value:
To select rows/columns of a data frame based on Label/Name:
Concatenate Data Frames: (by column)
Concatenate Data Frames: (by row)
Merging Data Frames: This works similar to SQL joins (left join, right, outer, inner)
- Merging based on a Column
- Outer join
- Left join
Reading External files:
Applying function to column/s in a data frame:
- By defining a function
- By using lambda (anonymous/nameless function)
Pivot table: this is similar to excel pivots
Identifying Unique values of a Column:
Handling missing values:
This brings us to the end of the blog on Pandas Cheat Sheet. Hope you find this helpful. If you wish to learn more about Python and it’s concepts, you can join Great Learning Academy’s Free Online Courses and learn more!0