According to one of the three methods of screening DateFrame

# encoding=utf-8

import pandas as pd
from pandasql import sqldf

ls = [ { 'id' : 1, 'time': 1, },{ 'id' : 2,'time': 3,}, {'id' : 3,'time': 3, }]

df = pd.DataFrame(ls)
print(df)

# 第一种:简单粗暴
print(df[df['time'] > 1])

# 第二种: pandassql的sqldf方法
pysqldf = lambda sql: sqldf(sql, globals())
sql = 'select * from df where time > 1'
print(pysqldf(sql))

# 第三种: where()  这种可读性更好些
df1 = df.where(cond=df['time'] > 1)
print(df1.dropna())

Guess you like

Origin www.cnblogs.com/gelu/p/19c832e4ae140831ec308979e379eeeb.html