python for data science ai & development coursera week 4 quiz answers

Practice Quiz

1. What are the most common modes used when opening a file?

  • (a)ppend, (r)edline, (w)rite
  • (s)ave, (r)ead, (w)rite
  • (a)ppend, (r)ead, (w)rite
  • (a)ppend, (c)lose, (w)rite

2. What is the data attribute that will return the title of the file?

  • File1.open()
  • File1.mode
  • File1.name
  • File1.close()

3. What is the command that tells Python to begin a new line?

  • \n
  • \q
  • \b
  • \e

4. What attribute is used to input data into a file?

  • File1.close()
  • File1.open()
  • File1.write()
  • File1.read()

5. What python object do you cast to a dataframe?

  • set
  • tuple
  • dictionary

6. How would you access the first-row and first column in the dataframe df?

  • df.ix[0,0]
  • df.ix[0,1]
  • df.ix[1,0]

7. What is the proper way to load a CSV file using pandas?

  • pandas.from_csv(‘data.csv’)
  • pandas.load_csv(‘data.csv’)
  • pandas.read_csv(‘data.csv’)
  • pandas.import_csv(‘data.csv’)

8. Use this dataframe to answer the question.

How would you select the Genre disco? Select all that apply.

  • df.iloc[6, ‘genre’]
  • df.loc[6, 5]
  • df.iloc[6, 4]
  • df.loc[‘Bee Gees’, ‘Genre’]

Shuffle Q/A 1

9. Use this dataframe to answer the question.

Which will NOT evaluate to 20.6? Select all that apply.

  • df.iloc[4,5]
  • df.iloc[6,5]
  • df.loc[4,’Music Recording Sales’]
  • df.iloc[6, ‘Music Recording Sales (millions)’]

10. Use this dataframe to answer the question.

How do we select Albums The Dark Side of the Moon to Their Greatest Hits (1971-1975)? Select all that apply.

  • df.iloc[2:5, ‘Album’]
  • df.loc[2:5, ‘Album’]
  • df.iloc[2:6, 1]
  • df.loc[2:5, 1]

Leave a Reply