很抱歉提出要求,但是我是python-noob,我需要帮助。
因此,我有这个csv(https://www.kaggle.com/jtrofe/beer-recipes),我需要提取某些值。
我想用相同的列和值创建一个新的数据框,但我想从“样式”列中仅提取“美国IPA,美国淡啤酒,赛森,美国淡啤酒和美国琥珀啤酒”。并以此创建一个数据框。
有人可以帮助我吗?
谢谢!
答案 0 :(得分:0)
import pandas as pd
# Read in the full data set, check its size
original_df = pd.read_csv('recipeData.csv', encoding='latin-1')
print(original_df.size) # 1698803
# Store your desired styles for filtering in a python list
styles_list = "American IPA, American Pale Ale, Saison, American Light Lager, American Amber Ale".split(', ')
# Filter using .loc and a boolean mask (checking if each 'Style' value is in your list)
new_df = original_df.loc[original_df['Style'].isin(styles_list)]
print(new_df.size) # 608419