DataFrames बनाना

pandas के साथ Data Manipulation

Maggie Matsui

Senior Content Developer at DataCamp

Dictionaries

my_dict = {
    "key1": value1,
    "key2": value2,
    "key3": value3
}
my_dict["key1"]
value1
my_dict = {
    "title": "Charlotte's Web",
    "author": "E.B. White",
    "published": 1952
}
my_dict["title"]
Charlotte's Web
pandas के साथ Data Manipulation

DataFrames बनाना

डिक्शनरी की सूची से

  • पंक्ति दर पंक्ति बनाया गया

 

कई डिक्शनरी वर्ग कोष्ठकों में दिखती हैं, जो डिक्शनरी की सूची दर्शाती हैं.

सूचियों की डिक्शनरी से

  • कॉलम दर कॉलम बनाया गया

 

एक डिक्शनरी में कई वर्ग कोष्ठक जोड़े दिखते हैं, जो सूचियों की डिक्शनरी दर्शाते हैं.

pandas के साथ Data Manipulation

डिक्शनरी की सूची - पंक्ति के हिसाब से

name breed height (cm) weight (kg) date of birth
Ginger Dachshund 22 10 2019-03-14
Scout Dalmatian 59 25 2019-05-09
list_of_dicts = [

{"name": "Ginger", "breed": "Dachshund", "height_cm": 22, "weight_kg": 10, "date_of_birth": "2019-03-14"},
{"name": "Scout", "breed": "Dalmatian", "height_cm": 59, "weight_kg": 25, "date_of_birth": "2019-05-09"}
]
pandas के साथ Data Manipulation

डिक्शनरी की सूची - पंक्ति के हिसाब से

name breed height (cm) weight (kg) date of birth
Ginger Dachshund 22 10 2019-03-14
Scout Dalmatian 59 25 2019-05-09
new_dogs = pd.DataFrame(list_of_dicts)
print(new_dogs)
     name      breed  height_cm  weight_kg date_of_birth
0  Ginger  Dachshund         22         10    2019-03-14
1   Scout  Dalmatian         59         25    2019-05-09
pandas के साथ Data Manipulation

सूचियों की डिक्शनरी - कॉलम के हिसाब से

name breed height weight date of birth
Ginger Dachshund 22 10 2019-03-14
Scout Dalmatian 59 25 2019-05-09

 

  • Key = कॉलम नाम
  • Value = कॉलम मानों की सूची
dict_of_lists = {

"name": ["Ginger", "Scout"],
"breed": ["Dachshund", "Dalmatian"],
"height_cm": [22, 59],
"weight_kg": [10, 25],
"date_of_birth": ["2019-03-14", "2019-05-09"]
}
new_dogs = pd.DataFrame(dict_of_lists)
pandas के साथ Data Manipulation

सूचियों की डिक्शनरी - कॉलम के हिसाब से

name breed height (cm) weight (kg) date of birth
Ginger Dachshund 22 10 2019-03-14
Scout Dalmatian 59 25 2019-05-09
print(new_dogs)
     name      breed  height_cm  weight_kg date_of_birth
0  Ginger  Dachshund         22         10    2019-03-14
1   Scout  Dalmatian         59         25    2019-05-09
pandas के साथ Data Manipulation

अभ्यास करते हैं!

pandas के साथ Data Manipulation

Preparing Video For Download...