np.genfromtxt() का इस्तेमाल
genfromtxt missing values या headers वाला text data load करता है, आपके लिए gaps भरते हुए।
In this page:
Syntax
data = np.genfromtxt("file.csv", delimiter=",", skip_header=1)
np.genfromtxt()
genfromtxt loadtxt से ज़्यादा forgiving reader है। यह headers skip कर सकता है, missing entries को nan या किसी दूसरी value से भरकर handle कर सकता है, और column names पढ़ सकता है। यह messy real-world data के लिए reach करने वाला tool है।
Note:
पहली row से column names लेने के लिए names=True इस्तेमाल करें।
उदाहरण: np.genfromtxt()
import numpy as np
import io
text = "1,2,3\n4,,6\n7,8,9"
a = np.genfromtxt(io.StringIO(text), delimiter=",")
print(a)
b = np.genfromtxt(io.StringIO(text), delimiter=",", filling_values=0)
print(b)
# Output:
# [[ 1. 2. 3.]
# [ 4. nan 6.]
# [ 7. 8. 9.]]
# [[1. 2. 3.]
# [4. 0. 6.]
# [7. 8. 9.]]
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- blanks वाली files पर loadtxt इस्तेमाल करना
- skip_header भूल जाना
- missing data के लिए filling_values न चुनना
चैप्टर सारांश
- genfromtxt missing data tolerate करता है
- skip_header lines skip करता है
- names=True एक header पढ़ता है
- Default से Missing values nan बनती हैं
🔒
Chapter Quiz — Complete all 5 topics to unlock
0/5 topics done
Complete these topics first: