21. What do the following lines of code do?

with open("Example.txt","a") as writefile:

writefile.write("This is line A\n")
writefile.write("This is line B\n")

  • Write to the file “Example.txt”
  • Read the file “Example.txt”
  • Append the file “Example.txt”

22 What task do the following lines of code perform?

with open('Example2.txt','r') as readfile:
with open('Example3.txt','w') as writefile:
for line in readfile:
writefile.write(line)

  • Copy the text from Example2.txt to Example3.txt.
  • Print out the content of Example2.txt.
  • Check the mode of the open function for each file object.

23. Consider the dataframe df. How would you access the element in the 2nd row and 1st column?

  • df.iloc[1,0]
  • df.iloc[2,1]
  • df.iloc[0,1]

24. In the lab, you learned you can also obtain a series from a dataframe df, select the correct way to assign the column with the header Length to a pandas series to the variable x.

  • x=df[‘Length’]
  • x=df[[‘Length’]]
  • x=df.[[‘Length’]]

Leave a Reply