# 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())

相关文章:

  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2021-05-16
  • 2022-12-23
  • 2021-12-16
  • 2022-02-19
猜你喜欢
  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
相关资源
相似解决方案