Computer scienceData scienceInstrumentsPandasStoring data with pandas

Combining Data in Pandas

Music store

Report a typo

We have the following DataFrames that store lists of musical instruments that we can buy in a music store, the identifier of their category, and average prices:

keyboard_instruments = pd.DataFrame({'cat_id': ['001', '002', '003'],
                                     'Instrument': ['Acoustic piano', 'Electric piano', 'Synthesizer'],
                                     'Average price': ['$10,000', '$5,000', '$1,200']},
                                    index=[1, 2, 3])

string_instruments = pd.DataFrame({'cat_id': ['004', '005', '006'],
                                   'Instrument': ['Acoustic guitar', 'Cello', 'Violin'],
                                   'Average price': ['$2,000', '$1,500', '$2,000']},
                                  index=[1, 2, 3])

After concatenation, we got the following dataset:

+----+----------+-----------------+-----------------+
|    |   cat_id | Instrument      | Average price   |
|----+----------+-----------------+-----------------|
|  0 |      001 | Acoustic piano  | $10,000         |
|  1 |      002 | Electric piano  | $5,000          |
|  2 |      003 | Synthesizer     | $1,200          |
|  3 |      004 | Acoustic guitar | $2,000          |
|  4 |      005 | Cello           | $1,500          |
|  5 |      006 | Violin          | $2,000          |
+----+----------+-----------------+-----------------+

Which parameters did we adjust to create this DataFrame? Write the body of the function concatenate_data() that will process two given datasets in the same way and return the resultant combined object. You do NOT need to call the function or print any results.

Write a program in Python 3
import pandas as pd

def concatenate_data(keyboard_instruments, string_instruments):
pass
___

Create a free account to access the full topic