शुरू करेंमुफ़्त में शुरू करें

pandas के साथ डेटा को ग्रुप करना

किसी डेटा पाइपलाइन का आउटपुट आमतौर पर एक "modeled" डेटासेट होता है. यह डेटासेट डेटा कंज़्यूमर्स को बिना ज़्यादा manipulation किए आसानी से जानकारी तक पहुँच देता है. pandas के साथ डेटा को group करना ऐसे modeled डेटासेट बनाने में मदद करता है.

pandas को pd के रूप में इम्पोर्ट किया गया है, और raw_testing_scores DataFrame में डेटा निम्न रूप में मौजूद है:

              street_address       city  math_score  reading_score  writing_score
01M539   111 Columbia Street  Manhattan       657.0          601.0          601.0
02M294      350 Grand Street  Manhattan       395.0          411.0          387.0
02M308      350 Grand Street  Manhattan       418.0          428.0          415.0

यह अभ्यास पाठ्यक्रम का हिस्सा है

Python में ETL और ELT

पाठ्यक्रम देखें

अभ्यास निर्देश

  • केवल "city", "math_score", "reading_score", और "writing_score" कॉलम रखने के लिए .loc[] का उपयोग करें.
  • DataFrame को "city" कॉलम के आधार पर group करें, और हर शहर के math, reading, और writing स्कोर का mean निकालें.
  • grouped DataFrame बनाने के लिए transform() फंक्शन का उपयोग करें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

def transform(raw_data):
	# Use .loc[] to only return the needed columns
	raw_data = raw_data.____[:, ____]
	
    # Group the data by city, return the grouped DataFrame
	grouped_data = raw_data.____(by=["____"], axis=0).____()
	return grouped_data

# Transform the data, print the head of the DataFrame
grouped_testing_scores = ____(raw_testing_scores)
print(grouped_testing_scores.head())
कोड संपादित करें और चलाएँ