Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 熊猫中类似SQL的语句?_Python_Sql_Pandas_Dataframe - Fatal编程技术网

Python 熊猫中类似SQL的语句?

Python 熊猫中类似SQL的语句?,python,sql,pandas,dataframe,Python,Sql,Pandas,Dataframe,我试图在pandas中运行以下SQL语句(显然是在Python代码中),但毫无进展: select year, contraction, indiv_count, total_words from dataframe where contraction in ("i'm","we're","we've","it's","they're") 其中,收缩是字符,年份,独立计数,总字数是整数 我对熊猫不太熟悉。如何在Python中创建类似的语句?如果您还没有阅读Anton评论中列出的文档,我

我试图在pandas中运行以下SQL语句(显然是在Python代码中),但毫无进展:

select year, contraction, indiv_count, total_words from dataframe
    where contraction in ("i'm","we're","we've","it's","they're")
其中,
收缩
字符
年份
独立计数
总字数
整数


我对熊猫不太熟悉。如何在Python中创建类似的语句?

如果您还没有阅读Anton评论中列出的文档,我建议您阅读这些文档,但是它缺少
.isin()
方法的文档,而这正是在
中复制SQL
所需要的

df[df['contraction'].isin(["i'm","we're","we've","it's","they're"])]

然后可以使用
.loc[]
或任何您最喜欢的方法(有很多)获得列选择。

您读过文档了吗?谢谢这两个答案都是我需要的。我只是没有在搜索中找到它们。这正是我从文档中找到的解决方案。谢谢