Pandas

kuniga.me > Docs > Pandas

Pandas

Create

From dictionary:

d = {'col1': [1, 2], 'col2': [3, 4]}
df = pd.DataFrame(data=d)

From dictionary of numpy arrays:

df = pd.DataFrame(
    {
        'a': np.array([1, 2, 3]),
        'b': np.array([4, 5, 6]),
    }
)

From numpy matrix:

df = pd.DataFrame(
    np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
    columns=['a', 'b', 'c']
)

From CSV file:

df = pd.read_csv('file.csv')

Filter rows

Filter rows where a given column satisfies a predicate:

filtered_df = df[df['value'] > 80]