相关疑难解决方法(0)

索引具有多个条件的Python Pandas数据帧SQL where where语句

我在R和Python Pandas的新手中很有经验.我试图索引一个DataFrame来检索满足一组几个逻辑条件的行 - 很像SQL的"where"语句.

我知道如何在R中使用数据帧(以及使用R的data.table包,这更像是Pandas DataFrame而不是R的本机数据帧).

下面是一些构建DataFrame的示例代码以及我想如何为其编制索引的说明.是否有捷径可寻?

import pandas as pd
import numpy as np

# generate some data
mult = 10000
fruits = ['Apple', 'Banana', 'Kiwi', 'Grape', 'Orange', 'Strawberry']*mult
vegetables = ['Asparagus', 'Broccoli', 'Carrot', 'Lettuce', 'Rutabaga', 'Spinach']*mult
animals = ['Dog', 'Cat', 'Bird', 'Fish', 'Lion', 'Mouse']*mult
xValues = np.random.normal(loc=80, scale=2, size=6*mult)
yValues = np.random.normal(loc=79, scale=2, size=6*mult)

data = {'Fruit': fruits,
        'Vegetable': vegetables, 
        'Animal': animals, 
        'xValue': xValues,
        'yValue': yValues,}

df = pd.DataFrame(data)

# shuffle the columns to break structure of repeating …
Run Code Online (Sandbox Code Playgroud)

python sql indexing pandas

9
推荐指数
1
解决办法
6800
查看次数

标签 统计

indexing ×1

pandas ×1

python ×1

sql ×1