Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Pandas dataframe passed to Python script is corrupted

Hi, I have a table that I download from a Salesforce report. One of the columns is the Saleforce case number and another one ('Defect')is a free text which may contain the string 'ABC-number', where...
  • Anonymous's avatar
    Anonymous
    3 years ago

    The response from Microsoft is that Power BI was not designed to handle embedded newlines - see here:

    https://community.powerbi.com/t5/Issues/Python-pandas-R-dataframes-passed-to-Python-R-script-are/idc-p/3017290#M90122.

     

    So the only solution is to "sanitize" the data before invoking Python or R.

    To do that, use the Table.ReplaceValue() in M Query, see below. All these actions can be invoked from the GUI.

     

    #"Duplicated Column" = Table.DuplicateColumn(#"some-previous-step", "Defect", "Defect - Copy")
    // Santize the new column
    #"Replaced Value" = Table.ReplaceValue(#"Duplicated Column","#(lf)","___",Replacer.ReplaceText,{"Defect-Copy"}),#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","#(cr)","___",Replacer.ReplaceText,{"Defect-Copy"}),
    // Must remove the original bad column
    #"Removed Columns1" = Table.RemoveColumns(#"Replaced Value1",{"Defect"}),
    // Rename the new column
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns1",{{"Defect-Copy", "DefectSanitized"}})