Forum Discussion
PowerQuery: python script converts unrelated text columns to int
- 3 years ago
The solution to this was that the ID column, despite being formatted as text in the data model, was not formatted as text properly.
When I tried to make it the key column of the table, PowerBI told me that it had nulls, and therefore it couldn't be used.
I removed the null, and hey presto - the Python script worked as it should.
Don't include that column in your dataframe?
Maybe you can show a sanitized version of your Power Query code.
When you write a Python script, the entire dataset is passed in as "dataset". I only actually do work on the text column - I don't mention the ID column at all. That's why this chewing up of that column is so strange.
I could create a new table with only the text column, and do the work on that - but then joining back to the OG table using the long text string as a key doesn't feel like best practice.
Here is my code:
import requests
import pandas as pd
def fix(x):
try:
return (requests.head(x,allow_redirects=True,timeout=1)).url
except:
return "Not available"
dataset['urls2'] = dataset['urls'].apply(lambda x: fix(x))