Skip to content

Commit 59773b2

Browse files
Added viewing_data_in_pandas.md file (animator#660)
* Add files via upload * Update classes.md * Update classes.md * Update classes.md * Update index.md * Update classes.md * Update index.md * Add files via upload * Update viewing_data_in_pandas.md * Delete contrib/advanced-python/classes.md * Delete contrib/advanced-python/index.md * Revert "Delete contrib/advanced-python/index.md" This reverts commit 55fe958. * Update index.md * Update viewing_data_in_pandas.md Updated the heading format * Update index.md * Update and rename viewing_data_in_pandas.md to viewing-data.md * Update viewing-data.md --------- Co-authored-by: Ankit Mahato <ankmahato@gmail.com>
1 parent ccd5dea commit 59773b2

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

contrib/pandas/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# List of sections
22

33
- [Pandas Introduction and Dataframes in Pandas](introduction.md)
4+
- [Viewing data in pandas](viewing-data.md)
45
- [Pandas Series Vs NumPy ndarray](pandas-series-vs-numpy-ndarray.md)
56
- [Pandas Descriptive Statistics](descriptive-statistics.md)
67
- [Group By Functions with Pandas](groupby-functions.md)

contrib/pandas/viewing-data.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Viewing rows of the frame
2+
3+
## `head()` method
4+
5+
The pandas library in Python provides a convenient method called `head()` that allows you to view the first few rows of a DataFrame. Let me explain how it works:
6+
- The `head()` function returns the first n rows of a DataFrame or Series.
7+
- By default, it displays the first 5 rows, but you can specify a different number of rows using the n parameter.
8+
9+
### Syntax
10+
11+
```python
12+
dataframe.head(n)
13+
```
14+
15+
`n` is the Optional value. The number of rows to return. Default value is `5`.
16+
17+
### Example
18+
19+
```python
20+
import pandas as pd
21+
df = pd.DataFrame({'animal': ['alligator', 'bee', 'falcon', 'lion','tiger','rabit','dog','fox','monkey','elephant']})
22+
df.head(n=5)
23+
```
24+
25+
#### Output
26+
27+
```
28+
animal
29+
0 alligator
30+
1 bee
31+
2 falcon
32+
3 lion
33+
4 tiger
34+
```
35+
36+
## `tail()` method
37+
38+
The `tail()` function in Python displays the last five rows of the dataframe by default. It takes in a single parameter: the number of rows. We can use this parameter to display the number of rows of our choice.
39+
- The `tail()` function returns the last n rows of a DataFrame or Series.
40+
- By default, it displays the last 5 rows, but you can specify a different number of rows using the n parameter.
41+
42+
### Syntax
43+
44+
```python
45+
dataframe.tail(n)
46+
```
47+
48+
`n` is the Optional value. The number of rows to return. Default value is `5`.
49+
50+
### Example
51+
52+
```python
53+
import pandas as pd
54+
df = pd.DataFrame({'fruits': ['mongo', 'orange', 'apple', 'lemon','banana','water melon','papaya','grapes','cherry','coconut']})
55+
df.tail(n=5)
56+
```
57+
58+
#### Output
59+
60+
```
61+
fruits
62+
5 water melon
63+
6 papaya
64+
7 grapes
65+
8 cherry
66+
9 coconut
67+
```

0 commit comments

Comments
 (0)