applymap() का उपयोग
applymap एक DataFrame के हर single cell पर एक function apply करता है।
In this page:
Syntax
df.applymap(function_name)
applymap()
DataFrame.applymap(func) हर element पर func call करता है और same shape का एक DataFrame return करता है। यह पूरी table format करने के लिए handy है। pandas 2.1 और बाद में same method का नाम DataFrame.map है, और applymap deprecated है।
Note:
pandas 1.x के लिए applymap और pandas 2.1 और newer के लिए DataFrame.map इस्तेमाल करें।
उदाहरण: applymap()
import pandas as pd
df = pd.DataFrame({"a": [1.234, 2.345], "b": [3.456, 4.567]})
print(df.applymap(lambda x: round(x, 1)))
# Output:
# a b
# 0 1.2 3.5
# 1 2.3 4.6
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. #}
आम गलतियां
- एक Series पर applymap इस्तेमाल करना
- जहाँ एक vectorized operation exist करती हो वहाँ इसे इस्तेमाल करना
- newer versions में deprecation ignore करना
चैप्टर सारांश
- applymap cell by cell काम करता है
- यह same-shape DataFrame return करता है
- Series इसकी बजाय map इस्तेमाल करते हैं
- pandas 2.1 में DataFrame.map नाम दिया गया
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: