How to read and open gal file from a selected path in my pc?

595 views Asked by At

I used python code to analyse my data. But when I wanted to read the gal file I got error.

w = pd.read_gal("C:\\Users\\Yousif\\Downloads\\PythonSpatial\\statess7.gal")

AttributeError Traceback (most recent call last) in () 1 ----> 2 w = pd.read("C:\Users\Yousif\Downloads\PythonSpatial\statess7.gal") 3

AttributeError: module 'pandas' has no attribute 'read'

Also once I used this function

w = pysal.open(pysal.examples.get_path("statess7.gal")).read()

I got this error

KeyError Traceback (most recent call last) in () 1 ----> 2 w = pysal.open(pysal.examples.get_path("statess7.gal")).read()

~\Anaconda3\lib\site-packages\pysal\examples__init__.py in get_path(example_name) 33 return os.path.join(base, 'examples', example_name) 34 else: ---> 35 raise KeyError(example_name + ' not found in PySAL built-in examples.') 36 37

KeyError: 'statess7.gal not found in PySAL built-in examples.'

I hope to find out how I can read and open gal file from path in my laptop.

1

There are 1 answers

3
Yobmod On

.gal are tab delimited, so could just try:

w = pd.read_table("C:\Users\Yousif\Downloads\PythonSpatial\statess7.gal")

(does pandas have a .read_gal method? I couldn't find it in the offical docs)

Edit: The above worked for me, but i had to set the encoding to get a readable dataframe,

df = pd.read_table("C:\path\file.gal", encoding="iso-8859-1")