एक से अधिक वर्कशीट से डेटा लेना

pandas के साथ सरल Data Ingestion

Amany Mahfouz

Instructor

लोड करने के लिए शीट चुनना

  • read_excel() डिफॉल्ट रूप से Excel फ़ाइल की पहली शीट लोड करता है
  • अन्य शीट लोड करने के लिए sheet_name आर्ग्युमेंट का उपयोग करें
  • शीट का नाम और/या (ज़ीरो-इंडेक्स्ड) पोज़िशन नंबर दें
  • एक साथ कई शीट लोड करने के लिए नाम/नंबर की सूची पास करें
  • read_excel() को दिए गए आर्ग्युमेंट सभी शीट पर लागू होते हैं
pandas के साथ सरल Data Ingestion

लोड करने के लिए शीट चुनना

स्प्रेडशीट प्रोग्राम का स्क्रीनशॉट, जिसमें दो स्प्रेडशीट के टैब दिख रहे हैं

pandas के साथ सरल Data Ingestion

चयनित शीट लोड करना

# Get the second sheet by position index
survey_data_sheet2 = pd.read_excel('fcc_survey.xlsx',
                                   sheet_name=1)

# Get the second sheet by name survey_data_2017 = pd.read_excel('fcc_survey.xlsx', sheet_name='2017')
print(survey_data_sheet2.equals(survey_data_2017))
True
pandas के साथ सरल Data Ingestion

सभी शीट लोड करना

  • read_excel() को sheet_name=None देने पर वर्कबुक की सभी शीट पढ़ी जाती हैं
survey_responses = pd.read_excel("fcc_survey.xlsx", sheet_name=None)

print(type(survey_responses))
<class 'collections.OrderedDict'>
for key, value in survey_responses.items():
    print(key, type(value))
2016 <class 'pandas.core.frame.DataFrame'>
2017 <class 'pandas.core.frame.DataFrame'>
pandas के साथ सरल Data Ingestion

सब कुछ साथ में जोड़ना

# Create empty dataframe to hold all loaded sheets
all_responses = pd.DataFrame()

# Iterate through dataframes in dictionary for sheet_name, frame in survey_responses.items(): # Add a column so we know which year data is from frame["Year"] = sheet_name
# Add the dataframe to all_responses all_responses = pd.concat([all_responses, frame])
# View years in data print(all_responses.Year.unique())
['2016' '2017']
pandas के साथ सरल Data Ingestion

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

pandas के साथ सरल Data Ingestion

Preparing Video For Download...