http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_excel.html
converters : dict, default None
Dict of functions for converting values in certain columns. Keys can either be integers or column labels, values are functions that take one input argument, the Excel cell content, and return the transformed content
例子如下:
df = pd.read_excel(r'D:\Projects\data.xlsx')
df['CLIENT_ID']
df = pd.read_excel(r'D:\Projects\data.xlsx', converters={'CLIENT_ID':str})
df['CLIENT_ID']
可以发现 dtype 并不是预想中的 str,而是object
所以当我在做如下判断时
In[9]: '3962302' in df['CLIENT_ID']
Out[9]: False
出现诡异的一幕,解决办法只能是多写一步操作
In[9]: '3962302' in df['CLIENT_ID']
Out[9]: False
In[10]: '3962302' in df['CLIENT_ID'].tolist()
Out[10]: True
In[11]: '3962302' in df['CLIENT_ID'].values
Out[11]: True
最后发现搞错了,并不是因为dtype变成了object,而是因为
'3962302' in df['CLIENT_ID']
#等同于
'3962302' in df['CLIENT_ID'].index