pandas 绘制前15个最高值的图形

k7fdbhmy  于 2022-12-28  发布在  其他
关注(0)|答案(1)|浏览(240)

我正在制作一个显示电影预算的数据集。我想制作一个包含前15个最高预算电影的情节。

#sort the 'budget' column in decending order and store it in the new dataframe.
info = pd.DataFrame(dp['budget'].sort_values(ascending = False))
info['original_title'] = dp['original_title']
data = list(map(str,(info['original_title'])))

#extract the top 10 budget movies data from the list and dataframe.
x = list(data[:10])
y = list(info['budget'][:10])

这就是我得到的结果

C:\Users\Phillip\AppData\Local\Temp\ipykernel_7692\1681814737.py:2: FutureWarning: The behavior of `series[i:j]` with an integer-dtype index is deprecated. In a future version, this will be treated as *label-based* indexing, consistent with e.g. `series[i]` lookups. To retain the old behavior, use `series.iloc[i:j]`. To get the future behavior, use `series.loc[i:j]`.
  y = list(info['budget'][:5])

我是数据分析领域的新手,所以我不知道该如何解决这个问题

mzaanser

mzaanser1#

一个简单的例子,使用电影数据集,我发现在线:

import pandas as pd

url = "https://raw.githubusercontent.com/erajabi/Python_examples/master/movie_sample_dataset.csv"
df = pd.read_csv(url)

# Bar plot of 15 highest budgets:
df.nlargest(n=15, columns="budget").plot.bar(x="movie_title", y="budget")

您可以通过向.bar(...)调用添加参数,以各种方式自定义绘图。

相关问题