4

I am trying to get a list of phone numbers

here is the code

response='108'
group="MAMA"
optout='False'

phone_numbers = merged_df.loc[(merged_df['Facility Code'] ==facility_number) & (merged_df['group'] == group) & (merged_df['Optedout'] == optout)]['phone'].values
    print(phone_numbers)

My dataframe looks like so

phone       group   County  PNC/ANC Facility Name   Optedout    Facility Code
25470000000 MAMA    Orange  PNC     Main Centre       FALSE      112
25470000000 MAMA    Orange  PNC     Main Centre       FALSE      112
25470000010 MAMA    Orange  PNC     Centre            FALSE      108
25470000020 MAMA    Orange  PNC     Centre            FALSE      108
25470000000 MAMA    Orange  PNC     Main Centre       FALSE      112

This is the error I get

AttributeError: 'Series' object has no attribute 'value'

desired output

[25470000010,25470000020]

I can't seem to figure out what I am doing wrong. kindly help me fix this

3
  • 1
    just drop the .values part Commented Apr 22, 2020 at 6:48
  • Remove .values. Commented Apr 22, 2020 at 6:49
  • 1
    A Series does have a values attribute. Could you have written value as the error suggests? Commented Apr 22, 2020 at 6:56

2 Answers 2

7

You need to remove .values:

phone_numbers = merged_df.loc[(merged_df['Facility Code'] ==facility_number) & (merged_df['group'] == group) & (merged_df['Optedout'] == optout)]['phone']
Sign up to request clarification or add additional context in comments.

Comments

2

@Serge Ballesta's comment is the most likely cause.

There are typos in the code that you have shared. Check whether you called value instead of values.

The following code works as expected:

import pandas as pd

data = {'phone': [25470000000, 25470000000, 25470000010, 25470000020, 25470000000], 'group': ['MAMA', 'MAMA', 'MAMA', 'MAMA', 'MAMA'], 'County': ['Orange', 'Orange', 'Orange', 'Orange', 'Orange'], 'PNC/ANC': ['PNC', 'PNC', 'PNC', 'PNC', 'PNC'], 'Facility Name': ['Main Centre', 'Main Centre', 'Centre', 'Centre', 'Main Centre'], 'Optedout': ['FALSE', 'FALSE', 'FALSE', 'FALSE', 'FALSE'], 'Facility Code': [112, 112, 108, 108, 112]}

merged_df = pd.DataFrame.from_dict(data)

facility_number = 108
group = 'MAMA'
optout = 'FALSE'

phone_numbers = merged_df.loc[(merged_df['Facility Code'] ==facility_number) & (merged_df['group'] == group) & (merged_df['Optedout'] == optout)]['phone'].values

print(phone_numbers)

Output:

[25470000010 25470000020]

By removing .values, the output is a dataframe:

2    25470000010
3    25470000020
Name: phone, dtype: int64

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.