• <small id='LLZ0s'></small><noframes id='LLZ0s'>

    1. <i id='LLZ0s'><tr id='LLZ0s'><dt id='LLZ0s'><q id='LLZ0s'><span id='LLZ0s'><b id='LLZ0s'><form id='LLZ0s'><ins id='LLZ0s'></ins><ul id='LLZ0s'></ul><sub id='LLZ0s'></sub></form><legend id='LLZ0s'></legend><bdo id='LLZ0s'><pre id='LLZ0s'><center id='LLZ0s'></center></pre></bdo></b><th id='LLZ0s'></th></span></q></dt></tr></i><div id='LLZ0s'><tfoot id='LLZ0s'></tfoot><dl id='LLZ0s'><fieldset id='LLZ0s'></fieldset></dl></div>
      <tfoot id='LLZ0s'></tfoot>

      • <bdo id='LLZ0s'></bdo><ul id='LLZ0s'></ul>

      <legend id='LLZ0s'><style id='LLZ0s'><dir id='LLZ0s'><q id='LLZ0s'></q></dir></style></legend>

        如何在 pandas 数据框列中选择一系列值?

        How to select a range of values in a pandas dataframe column?(如何在 pandas 数据框列中选择一系列值?)

      1. <tfoot id='jf4ds'></tfoot>

          • <i id='jf4ds'><tr id='jf4ds'><dt id='jf4ds'><q id='jf4ds'><span id='jf4ds'><b id='jf4ds'><form id='jf4ds'><ins id='jf4ds'></ins><ul id='jf4ds'></ul><sub id='jf4ds'></sub></form><legend id='jf4ds'></legend><bdo id='jf4ds'><pre id='jf4ds'><center id='jf4ds'></center></pre></bdo></b><th id='jf4ds'></th></span></q></dt></tr></i><div id='jf4ds'><tfoot id='jf4ds'></tfoot><dl id='jf4ds'><fieldset id='jf4ds'></fieldset></dl></div>
              <tbody id='jf4ds'></tbody>
          • <small id='jf4ds'></small><noframes id='jf4ds'>

            <legend id='jf4ds'><style id='jf4ds'><dir id='jf4ds'><q id='jf4ds'></q></dir></style></legend>
                <bdo id='jf4ds'></bdo><ul id='jf4ds'></ul>

                  本文介绍了如何在 pandas 数据框列中选择一系列值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  import pandas as pd
                  import numpy as np
                  data = 'filename.csv'
                  df = pd.DataFrame(data)
                  df 
                  
                          one       two     three  four   five
                  a  0.469112 -0.282863 -1.509059  bar   True
                  b  0.932424  1.224234  7.823421  bar  False
                  c -1.135632  1.212112 -0.173215  bar  False
                  d  0.232424  2.342112  0.982342  unbar True
                  e  0.119209 -1.044236 -0.861849  bar   True
                  f -2.104569 -0.494929  1.071804  bar  False
                  

                  我想为某一列选择一个范围,比如列 two.我想选择 -0.5 和 +0.5 之间的所有值.如何做到这一点?

                  I would like to select a range for a certain column, let's say column two. I would like to select all values between -0.5 and +0.5. How does one do this?

                  我希望使用

                  -0.5 < df["two"] < 0.5
                  

                  但这(自然)给出了一个ValueError:

                  But this (naturally) gives a ValueError:

                  ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
                  

                  我试过了

                  -0.5 (< df["two"] < 0.5)
                  

                  但这会输出所有 True.

                  正确的输出应该是

                  0    True
                  1    False
                  2    False
                  3    False
                  4    False
                  5    True
                  

                  在 pandas 数据框列中查找一系列值的正确方法是什么?

                  What is the correct way to find a range of values in a pandas dataframe column?

                  问题

                  使用 .between()

                  df['two'].between(-0.5, 0.5, inclusive=False)
                  

                  会有区别

                   -0.5 < df['two'] < 0.5
                  

                  和像

                   -0.5 =< df['two'] < 0.5
                  

                  ?

                  推荐答案

                  使用 betweeninclusive=False 表示严格不等式:

                  Use between with inclusive=False for strict inequalities:

                  df['two'].between(-0.5, 0.5, inclusive=False)
                  

                  inclusive 参数决定是否包含端点(True: <=, False: <).这适用于两个标志.如果您想要混合不等式,则需要明确编码:

                  The inclusive parameter determines if the endpoints are included or not (True: <=, False: <). This applies to both signs. If you want mixed inequalities, you'll need to code them explicitly:

                  (df['two'] >= -0.5) & (df['two'] < 0.5)
                  

                  这篇关于如何在 pandas 数据框列中选择一系列值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                  Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                  Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                  Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                  Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                  Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)
                  <i id='xnsLg'><tr id='xnsLg'><dt id='xnsLg'><q id='xnsLg'><span id='xnsLg'><b id='xnsLg'><form id='xnsLg'><ins id='xnsLg'></ins><ul id='xnsLg'></ul><sub id='xnsLg'></sub></form><legend id='xnsLg'></legend><bdo id='xnsLg'><pre id='xnsLg'><center id='xnsLg'></center></pre></bdo></b><th id='xnsLg'></th></span></q></dt></tr></i><div id='xnsLg'><tfoot id='xnsLg'></tfoot><dl id='xnsLg'><fieldset id='xnsLg'></fieldset></dl></div>
                    <bdo id='xnsLg'></bdo><ul id='xnsLg'></ul>
                    <legend id='xnsLg'><style id='xnsLg'><dir id='xnsLg'><q id='xnsLg'></q></dir></style></legend>
                  • <small id='xnsLg'></small><noframes id='xnsLg'>

                            <tfoot id='xnsLg'></tfoot>
                              <tbody id='xnsLg'></tbody>