I have this small little code here to import a SAS file into dataframe in Python.
JavaScript
x
5
1
from sas7bdat import SAS7BDAT
2
with SAS7BDAT('some_file.sas7bdat') as f:
3
df = f.to_data_frame()
4
print df.head(5)
5
The code runs forever without any output. The sas file I’m trying to import is 1.5gb.
Advertisement
Answer
You should use the native pandas function pandas.read_sas
it’s faster than iterating through the file as you did.
Here is the documentation of the pandas.read_sas
function. This code sample should be sufficient to load the file:
JavaScript
1
3
1
df = pandas.read_sas('some_file.sas7bdat')
2
print(df.head())
3