|
Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. Python lists are flexible but slow at scale. Enter NumPy - a Python library for fast numerical computing. It has arrays—a special data structure to store numbers efficiently. Arrays outperform regular Python lists in speed and memory. NumPy also has powerful math functions: statistics, linear algebra, random numbers, and more. Every major data science library - scikit learn, pandas, Tensorflow is built on top of it. Today we’ll start with basics — how to create and explore arrays. 🔫 Load/Import NumPy
In:
import numpy as np
🌀 List ➡ NumPy array
In:
data = [1, 2, 3, 4, 5] arr = np.array(data) print(arr)
Out:
[1 2 3 4 5]
ꪜ Make sure to check 'type'
In:
print(type(data)) print(type(arr))
Out:
📶 Generate range of numbers (start, end, interval)
In:
arr = np.arange(0, 10, 2) print(arr)
Out:
[0 2 4 6 8]
⚖ Produce evenly spaced numbers (start, end, num of items)
In:
arr = np.linspace(0, 1, 5) print(arr)
Out:
[0. 0.25 0.5 0.75 1. ]
🌌 Arrays can be multi dimensional as well
In:
arr2d = np.array([ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]) print(arr2d)
Out:
[[1 2 3] [4 5 6] [7 8 9]] 🧮 Count number of elements
In:
print(arr.size) print(arr2d.size)
Out:
5 9 🔶 Know shape (rows, columns) of array For 1D it tells the number of elements
In:
print(arr.shape) print(arr2d.shape)
Out:
(5,) (3, 3) 🏷️ dtype to find datatype of elements in array
In:
print(arr.dtype)
Out:
int64
📌 For float datatype
In:
arrfloat = np.array([10.1, 20.5, 30.3, 40, 50]) print(arrfloat.dtype)
Out:
float64
Quick Excel Shortcut 💡 Ctrl + Shift + ⭐📣 That's it for today! If you liked it, please share it with anyone who will find it useful and share your feedback below 🐼
|
Beginner to Expert in Python in just 5 minutes
Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. You have a spreadsheet with 500 numbers. Your boss asks: "What do you see?" Most will freeze, scroll, guess. Not you! 3 Python functions to turn raw numbers into answers. No calculator, excel sheets. Just code. Statistics isn't boring math. It's how you make decisions with data. Using just the statistics module we find "center" of any dataset. Any data analyst must know the basics‼️ 🎯 Compute simple...
Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. Last week we introduced numpy. Created bunch of arrays, sliced them and did some math with them. To prepare data for machine learning or any analysis, we need to learn to control their shape. Today - Reshape flat lists into grids. Flatten 2D tables back to 1D arrays. Create arrays filled with zeros, ones, or random numbers. ⏪ Recap: See dimensions first In: import numpy as np sales = np.array([120, 340,...
Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. TGIF! Everyone is talking about AI. Most people take courses. You're going to build it instead. Let's create a simple sentiment analyzer that reads customer reviews and classifies them as positive or negative. No machine learning libraries—just Python. 🎯 Define list of positive and negative words In: positive_words = ["good", "great", "excellent", "amazing", "love", "best"] negative_words = ["bad",...