MulaiMulai sekarang secara gratis

Manipulating data with Pandas

You can combine data from different sources into a single DataFrame.

Imagine that you are tasked with calculating GDP to understand the health of the US economy. You have gathered the data you need from disparate sources in different formats.

You can calculate gross domestic product using the supplied DataFrames for personal consumption expenditures, government expenditures, gross private domestic investment, and net exports. The DataFrames ge, gpdi, ne, and pce are provided.

Latihan ini adalah bagian dari kursus

Intermediate Python for Finance

Lihat Kursus

Petunjuk latihan

  • Combine the supplied source DataFrames ge, gpdi, ne and pce in that order into a single new DataFrame.
  • Sum the values in each row to produce the GDP per year.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Combine the source DataFrames into one
gdp = pd.____([ge, gpdi, ____, ____], axis=1)

# Add the columns and create a new column with the result
gdp['GDP'] = gdp.____(np.sum, axis=1)
Edit dan Jalankan Kode