Python Data Analysis Package Example

This article will discuss Data Analysis Python Packages. Python Packages are available from both Built-in and third parties. Built-in packages can be imported directly and used in code. A third-party package is needed for Installation. Examples are Pandas, Numpy, NLTK, etc.

Pandas

Open the command line and run the below command.

pip install pandas

Pandas package library is useful for data structures, manipulation, and analysis. DataFrames to the structured data, storing, indexing.

import pandas as pd

# Create a DataFrame for animals and their sounds
a = pd.DataFrame({
    'Animals': ['Dog', 'Cat', 'Lion', 'Cow', 'Elephant'],
    'Sounds': ['Barks', 'Meow', 'Roars', 'Moo', 'Trumpet']
})

# Display the DataFrame and its descriptive statistics
print(a)
print(a.describe())

# Create a DataFrame for letters and numbers
b = pd.DataFrame({
    "Letters": ['a', 'b', 'c', 'd', 'e', 'f'],
    "Numbers": [12, 7, 9, 3, 5, 1]
})

# Sort the DataFrame by the 'Numbers' column and display it
print(b.sort_values(by="Numbers"))

Output

   Animals   Sounds
0       Dog    Barks
1       Cat     Meow
2      Lion    Roars
3       Cow      Moo
4  Elephant  Trumpet

       Animals  Sounds
count        5       5
unique       5       5
top        Dog   Barks
freq         1       1

  Letters  Numbers
5       f        1
3       d        3
4       e        5
1       b        7
2       c        9
0       a       12

Numpy

Open the command line and run the below command.

pip install numpy

Once after; Installation run the code to verify the version.

import numpy as np

# Print the version of NumPy installed
print(np.__version__)

Numpy library is used for numerical computing like arrays and matrices, mathematical operations, s, and data structures.

import numpy as np

# Zeros function: print number of zeros
a = np.zeros(10)
print(a)

# Full function: create an array with a specific value
b = np.full((2, 10), 0.7)
print(b)

Output

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[[0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7]
[0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7]]  

NLTK

Natural Language Toolkit is a powerful library which is useful for with human language data. It supports tokenization, stemming, tagging, parsing, etc..

import nltk
from nltk.tokenize import word_tokenize

# Tokenize the text into words
text = "Natural Language Toolkit is a powerful library"
print(word_tokenize(text))

Output

['Natural', 'Language', 'Toolkit', 'is', 'a', 'powerful', 'library']


Similar Articles