程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

为什么数据框“df[column]”的值不等于“df[column].values”?(df[x][0] != df[x][0].values)?

发布于2023-05-30 00:28     阅读(758)     评论(0)     点赞(30)     收藏(4)


我无法解释这种行为。整数值显然在列中,但是当我运行“在”中时,我只在添加 .values 时得到 True

print(type(DF['Count']), type(df1['Count']))
print(type(DF['Count'][0]), type(df1['Count'][0]))

print(DF['Count'][0])
print(DF['Count'][0] in df1['Count'])
print(111223273 in df1['Count'])

print(DF['Count'][0])
print(DF['Count'][0] in df1['Count'].values)
print(111223273 in df1['Count'].values)
<class 'pandas.core.series.Series'> <class 'pandas.core.series.Series'>
<class 'numpy.int64'> <class 'numpy.int64'>

532578307
False
False

532578307
True
True
DF.head(5).to_dict()

{'COL0': {0: 'TEXT 0', 1: 'TEXT 1', 2: 'TEXT 2', 3: 'TEXT 3', 4: 'TEXT 4'},
 'COL1': {0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0},
 'COL2': {0: Timestamp('2010-01-19 00:00:00'),
  1: Timestamp('2010-01-19 00:00:00'),
  2: Timestamp('2010-01-19 00:00:00'),
  3: Timestamp('2010-01-19 00:00:00'),
  4: Timestamp('2010-01-19 00:00:00')},
 'COL3': {0: 'TEXT 0', 1: 'TEXT 1', 2: 'TEXT 2', 3: 'TEXT 3', 4: 'TEXT 4'},
 'COL4': {0: 'TEXT 0', 1: 'TEXT 1', 2: 'TEXT 2', 3: 'TEXT 3', 4: 'TEXT 4'},
 'COL5': {0: NaT, 1: NaT, 2: NaT, 3: NaT, 4: NaT},
 'COL6': {0: 'CA', 1: 'CA', 2: 'CA', 3: 'CA', 4: 'CA'},
 'COL7': {0: Timestamp('2012-10-31 00:00:00'),
  1: Timestamp('2012-11-30 00:00:00'),
  2: Timestamp('2012-12-31 00:00:00'),
  3: Timestamp('2013-01-31 00:00:00'),
  4: Timestamp('2013-02-28 00:00:00')},
 'COL8': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL9': {0: 532578307,
  1: 532578307,
  2: 532578307,
  3: 532578307,
  4: 532578307},
 'COL10': {0: 240, 1: 240, 2: 240, 3: 240, 4: 240},
 'COL11': {0: 33, 1: 34, 2: 35, 3: 36, 4: 37},
 'COL12': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL13': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL14': {0: 0.04125, 1: 0.04125, 2: 0.04125, 3: 0.04125, 4: 0.04125},
 'COL15': {0: 0.04125, 1: 0.04125, 2: 0.04125, 3: 0.04125, 4: 0.04125},
 'COL16': {0: 306590.89, 1: 302577.2, 2: 300549.6, 3: 300549.6, 4: 299530.57},
 'COL17': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL18': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL19': {0: 335000.0, 1: 335000.0, 2: 335000.0, 3: 335000.0, 4: 335000.0},
 'COL20': {0: 8.38, 1: 8.38, 2: 8.38, 3: 8.38, 4: 8.38},
 'COL21': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL22': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL23': {0: 1, 1: 1, 2: 1, 3: 1, 4: 1},
 'COL24': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL25': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL26': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL27': {0: 100, 1: 100, 2: 100, 3: 100, 4: 100},
 'COL28': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL29': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL30': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL31': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL32': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL33': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL34': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL35': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL36': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL37': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL38': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL39': {0: '', 1: '', 2: '', 3: '', 4: ''},
 'COL40': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL41': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL42': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL43': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL44': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL45': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL46': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL47': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL48': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL49': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL50': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL51': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL52': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL53': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL54': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL55': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL56': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL57': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL58': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL59': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL60': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL61': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL62': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL63': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL64': {0: 100, 1: 100, 2: 100, 3: 100, 4: 100},
 'COL65': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL66': {0: 100, 1: 100, 2: 100, 3: 100, 4: 100},
 'COL67': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL68': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL69': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL70': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL71': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL72': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL73': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL74': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL75': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL76': {0: 100, 1: 100, 2: 100, 3: 100, 4: 100},
 'COL77': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL78': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL79': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL80': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL81': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL82': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL83': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL84': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL85': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL86': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL87': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL88': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL89': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL90': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL91': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL92': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL93': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL94': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL95': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL96': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL97': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL98': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL99': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL100': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL101': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL102': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL103': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL104': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL105': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL106': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL107': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL108': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL109': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL110': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL111': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL112': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL113': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL114': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL115': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL116': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL117': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL118': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL119': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL120': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL121': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL122': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'COL123': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL124': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL125': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL126': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL127': {0: 96146.0, 1: 96146.0, 2: 96146.0, 3: 96146.0, 4: 96146.0},
 'COL128': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL129': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL130': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL131': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL132': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL133': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL134': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL135': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL136': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL137': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL138': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL139': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL140': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL141': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL142': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL143': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL144': {0: 306590.89, 1: 302577.2, 2: 300549.6, 3: 300549.6, 4: 299530.57},
 'COL145': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL146': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL147': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL148': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL149': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL150': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL151': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL152': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL153': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'COL154': {0: 532578307,
  1: 532578307,
  2: 532578307,
  3: 532578307,
  4: 532578307}}
df1.head(5).to_dict()

{'column0': {0: 'Content 0',
  1: 'Content 1',
  2: 'Content 2',
  3: 'Content 3',
  4: 'Content 4'},
 'column1': {0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0},
 'column2': {0: Timestamp('2010-01-19 00:00:00'),
  1: Timestamp('2010-01-19 00:00:00'),
  2: Timestamp('2010-01-19 00:00:00'),
  3: Timestamp('2010-01-19 00:00:00'),
  4: Timestamp('2010-01-19 00:00:00')},
 'column3': {0: 'Content 0',
  1: 'Content 1',
  2: 'Content 2',
  3: 'Content 3',
  4: 'Content 4'},
 'column4': {0: 'Content 0',
  1: 'Content 1',
  2: 'Content 2',
  3: 'Content 3',
  4: 'Content 4'},
 'column5': {0: NaT, 1: NaT, 2: NaT, 3: NaT, 4: NaT},
 'column6': {0: 'CA', 1: 'CA', 2: 'CA', 3: 'CA', 4: 'CA'},
 'column7': {0: Timestamp('2012-10-31 00:00:00'),
  1: Timestamp('2012-11-30 00:00:00'),
  2: Timestamp('2012-12-31 00:00:00'),
  3: Timestamp('2013-01-31 00:00:00'),
  4: Timestamp('2013-02-28 00:00:00')},
 'column8': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column9': {0: 532578307,
  1: 532578307,
  2: 532578307,
  3: 532578307,
  4: 532578307},
 'column10': {0: 240, 1: 240, 2: 240, 3: 240, 4: 240},
 'column11': {0: 33, 1: 34, 2: 35, 3: 36, 4: 37},
 'column12': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column13': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column14': {0: 0.04125, 1: 0.04125, 2: 0.04125, 3: 0.04125, 4: 0.04125},
 'column15': {0: 0.04125, 1: 0.04125, 2: 0.04125, 3: 0.04125, 4: 0.04125},
 'column16': {0: 306590.89,
  1: 302577.2,
  2: 300549.6,
  3: 300549.6,
  4: 299530.57},
 'column17': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column18': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column19': {0: 335000.0, 1: 335000.0, 2: 335000.0, 3: 335000.0, 4: 335000.0},
 'column20': {0: 8.38, 1: 8.38, 2: 8.38, 3: 8.38, 4: 8.38},
 'column21': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column22': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column23': {0: 1, 1: 1, 2: 1, 3: 1, 4: 1},
 'column24': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column25': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column26': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column27': {0: 100, 1: 100, 2: 100, 3: 100, 4: 100},
 'column28': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column29': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column30': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column31': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column32': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column33': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column34': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column35': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column36': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column37': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column38': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column39': {0: '', 1: '', 2: '', 3: '', 4: ''},
 'column40': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column41': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column42': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column43': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column44': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column45': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column46': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column47': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column48': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column49': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column50': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column51': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column52': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column53': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column54': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column55': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column56': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column57': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column58': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column59': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column60': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column61': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column62': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column63': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column64': {0: 100, 1: 100, 2: 100, 3: 100, 4: 100},
 'column65': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column66': {0: 100, 1: 100, 2: 100, 3: 100, 4: 100},
 'column67': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column68': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column69': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column70': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column71': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column72': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column73': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column74': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column75': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column76': {0: 100, 1: 100, 2: 100, 3: 100, 4: 100},
 'column77': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column78': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column79': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column80': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column81': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column82': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column83': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column84': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column85': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column86': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column87': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column88': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column89': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column90': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column91': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column92': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column93': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column94': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column95': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column96': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column97': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column98': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column99': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column100': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column101': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column102': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column103': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column104': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column105': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column106': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column107': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column108': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column109': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column110': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column111': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column112': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column113': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column114': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column115': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column116': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column117': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column118': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column119': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column120': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column121': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column122': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0},
 'column123': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column124': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column125': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column126': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column127': {0: 96146.0, 1: 96146.0, 2: 96146.0, 3: 96146.0, 4: 96146.0},
 'column128': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column129': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column130': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column131': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column132': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column133': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column134': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column135': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column136': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column137': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column138': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column139': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column140': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column141': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column142': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column143': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column144': {0: 306590.89,
  1: 302577.2,
  2: 300549.6,
  3: 300549.6,
  4: 299530.57},
 'column145': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column146': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column147': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column148': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column149': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column150': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column151': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column152': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column153': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan},
 'column154': {0: 532578307,
  1: 532578307,
  2: 532578307,
  3: 532578307,
  4: 532578307}}

Jupyter 笔记本快照

我添加了 Jupyter notebook 的图像以更清楚地显示正在发生的事情。我很困惑,不明白为什么会这样。

我尝试转换所有类型,确保它们相同:系列、整数。确保价值在那里。但是当我在没有 .values 后缀的情况下查找它时,它仍然给我 False 。


解决方案


in在 Pandas Series 或 NumPy 数组上使用运算符实际上是略有不同的操作。

对于 NumPy 数组,它遍历数组,并将每个元素与您要搜索的元素进行比较。

对于 Pandas 系列,它迭代系列的索引,并将每个元素与您正在搜索的元素进行比较

这是两者如何不同意的示例:

代码:

import pandas as pd

df = pd.DataFrame({'x': range(1000, 1010)})
print(df)
print()
print(f"{1001 in df['x']=}")
print(f"{1001 in df['x'].values=}")

print(f"{1 in df['x']=}")
print(f"{1 in df['x'].values=}")

输出:

      x
0  1000
1  1001
2  1002
3  1003
4  1004
5  1005
6  1006
7  1007
8  1008
9  1009

1001 in df['x']=False
1001 in df['x'].values=True
1 in df['x']=True
1 in df['x'].values=False

另请参阅:将 in 运算符与 Pandas 系列一起使用



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:https://www.pythonheidong.com/blog/article/1983588/2e18f3ceb539d2f171f0/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

30 0
收藏该文
已收藏

评论内容:(最多支持255个字符)