我正在尝试使用Pandas创建一个经过过滤的数据框,并根据条件使用matplotlib将其显示出来,但是当我尝试将项目添加到一个空列表中时,该列表没有按照条件进行过滤,而是包含了csv中的所有元素。
这是我的代码:
from matplotlib import pyplot as plt
import pandas as pd
plt.style.use('ggplot')
df = pd.read_csv('C:/Users/Gemxs/Documents/Python/Pandas/pokemon.csv')
fig1, (Legendary, Normal) = plt.subplots(nrows=2, ncols=1)
total_pokemon = []
generation_list = []
legendaries = df[df['Legendary'] == True]
total_for_legendaries = df['Total']
generation_for_legendaries = df['Generation']
normals = df[df['Legendary'] == False]
total_for_normals = df[df['HP'] < 500]
for index, row in df.iterrows():
if row['Total'] > 500:
total_pokemon.append(row['Total'])
print(total_pokemon)
我想将大于500的元素发送到空列表中。