Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
n_nnouchi
Regular Visitor

"Object reference not set to an instance of an object" Python dataset

I have a dataset generated through a Python script that is giving me this error ("Object reference not set to an instance of an object") whenever I attempt to refresh the latest information from its source.

 

There doesn't appear to be any issues with establishing the connection or editing it in the Power Query Editor. I've ensured that there are no null values in any of the records and have changed privacy settings but no luck so far.

 

My report has one semantic model (Direct Query import) that is used for all of the other tables and has a relationship with the Python dataset that is imported into the file. 

 

What are your recommendations on resolving this issue? I do not have a Microsoft Fabric license and would like to avoid having to upgrade or use a trial to utilize a Notebook.

 

 

Below is an example of the script I'm running in my workbook.

 

 

 

from simple_salesforce import Salesforce

import pandas as pd

 
    
sf = Salesforce(

    username="xxx",

    password="xxx",

    security_token="xxx",

)



# Query Salesforce

soql = """

    SELECT 
    Name, 
    xxx,
    Task
FROM Project

"""

results = sf.query_all(soql)
 
# Extract records and normalize
records = results["records"]

project_tasks = pd.json_normalize(records)

project_tasks = project_tasks.drop(columns=[col for col in project_tasks.columns if 'attribute' in col.lower()], errors="ignore")

# List the columns not aggregated by the unpivot
id_cols = ['Name', 'xxx']

# Perform the unpivot (melt)
melted_df = pd.melt(
    project_tasks,
    id_vars=id_cols,
    value_vars=[col for col in project_tasks.columns if col not in id_cols],
    var_name='Task',
    value_name='xxx'
)

# Clean up the task names by removing the _Hours suffix and __c
melted_df['Task'] = melted_df['Task'].str.replace('xxx', '')

# Capitalize each word in the task name
melted_df['Task'] = melted_df['Task'].str.title()

# Drop rows where Hours is null
melted_df = melted_df.dropna(subset=['xxx'])

# Fill in melted_df column 'Project Name' blank records with 'No Project Associated'
melted_df['xxx'] = melted_df['xxx'].fillna('No Project Associated')

# Sort by identifier columns and task
melted_df = melted_df.sort_values(by=id_cols + ['Task'])

# melted_df.to_csv('project_tasks.csv', index=False)

# return dataframe
melted_df = melted_df.drop(columns=['xxx'])
print(melted_df)

 

 

 

Please let me know if you need any further information.

 

Thanks!

4 REPLIES 4
lbendlin
Super User
Super User

How do you obtain the token, and how do you ensure it is still valid?

 

Why not use the native SalesForce Object connector?

The token is valid as my query is pulling exactly what I want for this dataset. It is easier to manipulate the object with Python rather than using the Salesforce connector in my opinion.

 

However, I'm mainly curious on why I would have the error message: "Object reference not set to an instance of an object".

That doesn't appear to solve the issue.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.