Convert SAS file to csv file.
If you have file_name.sas7bdat and you would like to convert into normal csv file without UnicodeDecodeError character issue then below code.
>>>>>>>>Python code>>>>>>>>>>>>>>
from dataiku import pandasutils as pdu
df = pd.read_sas('/path/file_name.sas7bdat')
for col in df.columns:
if df[col].dtype == 'object':
df[col] = df[col].apply(lambda x: x.decode('utf-8') if isinstance(x, bytes) else x)
print(df)
========================================================================================
Try this if above one didn't work.
import dataiku
import pandas as pd, numpy as np
from dataiku import pandasutils as pdu
import os
import glob
df = pd.read_sas(dataiku.get_custom_variables()["v_sg_cust_path"]+'/'+dataiku.get_custom_variables()["v_file"])
df= df.apply(lambda x: x.decode() if isinstance(x, bytes) else x)
# Write recipe outputs
landing = dataiku.Dataset("landing")
landing.write_with_schema(df)
Comments
Post a Comment