Exercise_week8

html

School

Northeastern University *

*We aren’t endorsed by this school

Course

5010

Subject

English

Date

Dec 6, 2023

Type

html

Pages

2

Uploaded by CoachMusic12879

Report
In [ ]: cd In [ ]: import datetime print(datetime.datetime.now()) 1. #### Question1 Write a code snippet that opens a file named messages.txt in write mode and writes 3 different messages to it, each on a new line. Please complete the following code: messages_file = open() messages_file.write() messages_file.close() messages_file = open() print() In [1]: messages_file = open("messages.txt", "w") messages_file.write("Hello everyone\n") messages_file.write("This is Sahitya\n") messages_file.write("All the best for the exam\n") messages_file.close() messages_file = open("messages.txt", "r") print(messages_file.read()) messages_file.close() Hello everyone This is Sahitya All the best for the exam 1. #### Question2 Given a DataFrame named population with columns Country_Name , Year , and Population , write code to select rows 2 to 5 (inclusive) only for the columns Country_Name and Year . In [2]: import pandas as pd population = pd.DataFrame({'Country_Name': ['Germany', 'India', 'United States', 'United Kingdom', 'Australia'], 'Year': [2023, 2023, 2023, 2023, 2023], 'Population': [1543, 1580, 731, 673, 111]}) def g(population): return population.iloc[1:6, :2] result = g(population.copy()) print(result) Country_Name Year
1 India 2023 2 United States 2023 3 United Kingdom 2023 4 Australia 2023 In [ ]:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help