Вы можете использовать df.unstack('continent')
для размещения континента в качестве столбцов, тогда этот информационный кадр становится 2D-таблицей, где 1-й столбец - это X, а другие столбцы - Y. Вы можете напрямую вызвать функцию plot
или управлять графиком самостоятельно,Операции с сырым matplotlib.
Спасибо за ваши данные, вот полный пример кода для вашего запроса:
# imports
import pandas as pd
import matplotlib.pyplot as plt
# prepare dataframe
df = pd.read_csv('gapminder.tsv', sep='\t')
df = df.groupby(['year','continent']).lifeExp.mean()
# unstack the `continent` index, to place it as columns
df = df.unstack(level='continent')
# The name of columns would become the name of legend
# when using dataframe plot
df.columns.name = 'Life Expectation'
# Now, we have a 2d talbe, 1st column become to X
# and other columns become to Y
# In [14]: df.head()
# Out[14]:
# Life Expectation Africa Americas Asia Europe Oceania
# year
# 1952 39.135500 53.27984 46.314394 64.408500 69.255
# 1957 41.266346 55.96028 49.318544 66.703067 70.295
# 1962 43.319442 58.39876 51.563223 68.539233 71.085
# 1967 45.334538 60.41092 54.663640 69.737600 71.310
# 1972 47.450942 62.39492 57.319269 70.775033 71.910
# matplotlib operations
# Here we use dataframe plot function
# You could also use raw matplotlib plot one column each to do fine control
# Please polish the figure with more configurations
fig, ax = plt.subplots(figsize=(6, 4.5))
df.plot()
Есть несколько хитростей в обработке данных, пожалуйста, проверьте комментарии в коде,Черновой график выглядит так: 
Пожалуйста, отшлифуйте свою фигуру с помощью большего количества операций с matplotlib.Например:
- Установить метку y
- Высоту двух больших, установить легенду на два столбца, чтобы уменьшить ее
- Цвета линии или формылиния
- Линия с маркерами?
Вот некоторые настройки
# set axis labels
ax.set_xlabel('Year')
ax.set_ylabel('Life Expection')
# set markers
markers = ['o', 's', 'd', '^', 'v']
for i, line in enumerate(ax.get_lines()):
line.set_marker(markers[i])
# update legend
ax.legend(ax.get_lines(), df.columns, loc='best', ncol=2)
plt.tight_layout()
Фигура теперь выглядит так: 