Attributeerror: 'Series' Object Has No Attribute 'Value'

Attributeerror: 'Series' Object Has No Attribute 'Value'

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

2 Answers

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']

@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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.