kopia lustrzana https://github.com/animator/learn-python
Added viewing_data_in_pandas.md file (#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 55fe958c1c
.
* 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>
pull/721/head
rodzic
ccd5dea51e
commit
59773b20ee
|
@ -1,6 +1,7 @@
|
|||
# List of sections
|
||||
|
||||
- [Pandas Introduction and Dataframes in Pandas](introduction.md)
|
||||
- [Viewing data in pandas](viewing-data.md)
|
||||
- [Pandas Series Vs NumPy ndarray](pandas-series-vs-numpy-ndarray.md)
|
||||
- [Pandas Descriptive Statistics](descriptive-statistics.md)
|
||||
- [Group By Functions with Pandas](groupby-functions.md)
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
# Viewing rows of the frame
|
||||
|
||||
## `head()` method
|
||||
|
||||
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:
|
||||
- The `head()` function returns the first n rows of a DataFrame or Series.
|
||||
- By default, it displays the first 5 rows, but you can specify a different number of rows using the n parameter.
|
||||
|
||||
### Syntax
|
||||
|
||||
```python
|
||||
dataframe.head(n)
|
||||
```
|
||||
|
||||
`n` is the Optional value. The number of rows to return. Default value is `5`.
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
import pandas as pd
|
||||
df = pd.DataFrame({'animal': ['alligator', 'bee', 'falcon', 'lion','tiger','rabit','dog','fox','monkey','elephant']})
|
||||
df.head(n=5)
|
||||
```
|
||||
|
||||
#### Output
|
||||
|
||||
```
|
||||
animal
|
||||
0 alligator
|
||||
1 bee
|
||||
2 falcon
|
||||
3 lion
|
||||
4 tiger
|
||||
```
|
||||
|
||||
## `tail()` method
|
||||
|
||||
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.
|
||||
- The `tail()` function returns the last n rows of a DataFrame or Series.
|
||||
- By default, it displays the last 5 rows, but you can specify a different number of rows using the n parameter.
|
||||
|
||||
### Syntax
|
||||
|
||||
```python
|
||||
dataframe.tail(n)
|
||||
```
|
||||
|
||||
`n` is the Optional value. The number of rows to return. Default value is `5`.
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
import pandas as pd
|
||||
df = pd.DataFrame({'fruits': ['mongo', 'orange', 'apple', 'lemon','banana','water melon','papaya','grapes','cherry','coconut']})
|
||||
df.tail(n=5)
|
||||
```
|
||||
|
||||
#### Output
|
||||
|
||||
```
|
||||
fruits
|
||||
5 water melon
|
||||
6 papaya
|
||||
7 grapes
|
||||
8 cherry
|
||||
9 coconut
|
||||
```
|
Ładowanie…
Reference in New Issue