Before any data manipulation can occur, one (1) new library will require installation:
- The Pandas library enables access to/from a DataFrame.
To install this library, navigate to an IDE terminal. At the command prompt (
$), execute the code below. For the terminal used in this example, the command prompt is a dollar sign (
$). Your terminal prompt may be different.
$ pip install pandas
<Enter> key on the keyboard to start the installation process.
If the installations were successful, a message displays in the terminal indicating the same.
Feel free to view the PyCharm installation guide for the required library.
Add the following code to the top of each code snippet. This snippet will allow the code in this article to run error-free.
import pandas as pd
💡 Note: To follow along with the examples below, click here to download the
finxters.csv file of auto-generated dummy user data. Move this file to the current working directory.
DataFrame head() and tail()
These methods display n numbers of records (top or bottom). These methods are useful when you are accessing large amounts of data.
If no parameter is entered, by default, five (5) rows display.
head()method returns the top five (5) rows of the DataFrame.
tail()method returns the bottom five (5) rows of the DataFrame
If a parameter is entered in one of the above methods, n number of rows (top/bottom) will display.
As you will note, the
head() method was accessed many times during this article. Both methods are must-haves in your knowledge base.
The syntax for these methods is as follows:
|An integer value indicating the number of rows to display. By default, five (5) rows display.|
For this example, the first five (5) records from the DataFrame and the last five (5) records (tail) from the same DataFrame display.
df_fxs = pd.read_csv('finxters.csv') print(df_fxs.head()) print(df_fxs.tail())
More Pandas DataFrame Methods
Feel free to learn more about the previous and next pandas DataFrame methods (alphabetically) here:
Also, check out the full cheat sheet overview of all Pandas DataFrame methods.
At university, I found my love of writing and coding. Both of which I was able to use in my career.
During the past 15 years, I have held a number of positions such as:
In-house Corporate Technical Writer for various software programs such as Navision and Microsoft CRM
Corporate Trainer (staff of 30+)
Implementation Specialist for Navision and Microsoft CRM
Senior PHP Coder