0

I have a code that used to work for a large dataset in which I read and filter call center records. Suddenly, the code quit working with my latest Anaconda upgrade.

To test the code, I have created a super simple 3x2 dataframe to troubleshoot why the isin function isn't working anymore. I can't figure it out.

Here is what I tried:

This first step works well

import pandas as pd
test_df = pd.read_csv('testfile.csv')

The output for my new data frame is:

8003002419
8005555555
8003002419

Now I want all rows with a specific phone number to go into its own data frame.

mytfn = ['8003002419']
result_df = test_df[test_df['TFN'].isin(mytfn)]

result_df

The result comes up blank

wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • You need to check the datatypes. Pandas is probably converting your phone numbers to integers. See if `mytfn=[8003002419]` works – Tim Roberts Nov 14 '22 at 18:12
  • It looks like those are getting read as ints, not strings. I've linked a question that explains how to keep them as strings. BTW, welcome to Stack Overflow! Check out the [tour], and for tips, see [ask] and [How to make good reproducible pandas examples](/q/20109391/4518341). – wjandrea Nov 14 '22 at 18:16
  • @TimRoberts Don't use integers for phone numbers. For example, if you had international numbers in the data set, the leading `0`s or `+` would get stripped, which would break them. – wjandrea Nov 14 '22 at 18:18
  • Thank you both. .info() does show my phone numbers were converted to integers. I made the change you suggested and it worked! Now I can follow the link to how to keep them as strings. – Kendall Davis Nov 14 '22 at 18:57

0 Answers0