4.2 dtypes
| dtype | Use |
|---|---|
int64 / int32 |
Counts, qty |
float64 |
Amounts, minutes |
bool |
Flags |
object |
Mixed / text (slow) |
amount_txt = np.array(["64", "90", "240"])
# wrong for math — convert:
amount_num = amount_txt.astype(float)
print(amount_num.sum())
Ravindra Bagale's Tip
Amounts that come from a CSV often arrive as text, so a sum gives an error or a wrong result. In NumPy, convert them with astype(float) and check the dtype before you add them. The same idea is behind astype and pd.to_numeric() in pandas, so learn dtypes well here.
Ravindra Bagale's Tip – मराठी
CSV मधून आलेल्या amounts बऱ्याचदा text म्हणून येतात, त्यामुळे sum केल्यावर error येतो किंवा चुकीचा result मिळतो. NumPy मध्ये त्यांना astype(float) ने convert करा आणि बेरीज करण्याआधी dtype तपासा. pandas मधल्या astype आणि pd.to_numeric() मागेही हीच कल्पना आहे, म्हणून dtypes इथेच नीट समजून घ्या.
Ravindra Bagale's Tip – हिंदी
CSV से आए amounts अक्सर text के रूप में आते हैं, इसलिए sum करने पर error आता है या ग़लत result मिलता है। NumPy में उन्हें astype(float) से convert करो और जोड़ने से पहले dtype जाँचो। pandas के astype और pd.to_numeric() के पीछे भी यही idea है, इसलिए dtypes यहीं अच्छे से समझ लो।