Neeraj Baheti
Neeraj Baheti

Reputation: 11

pandas read_csv function reading values as NaN even though there are values in cells

I have a file that I am trying to read in a pandas dataframe. However, some of the cells, are coming up as NaN even though there are values in there. The cells that are showing up as float value. The cells that are not showing up were copied pasted in the cells. Not sure why that would make a difference. Can anyone help? I have included the file as a link at this location: https://www.dropbox.com/s/30rxw07eaza29df/manhattan_hs_gps.csv?dl=0

dataframe output

Upvotes: 1

Views: 337

Answers (1)

NYC Coder
NYC Coder

Reputation: 7604

Tried this and it worked fine, both encoding='unicode-escape' and encoding='latin-1' work:

df = pd.read_csv('manhattan_hs_gps.csv', encoding='unicode-escape', header=None)
print(df)

       0                                                  1          2          3
0      0              A. Philip Randolph Campus High School  40.818500 -73.950000
1      1                                       Aaron School  40.744800 -73.983700
2      2                      Abraham Joshua Heschel School  40.772300 -73.989700
3      3  Academy of Environmental Science Secondary Hig...  40.785200 -73.942200
4      4  Academy for Social Action: A College Board School  40.815400 -73.955300
..   ...                                                ...        ...        ...
162  164                                 Xavier High School  40.737900 -73.994600
163  165            Yeshiva University High School for Boys  40.851749 -73.928695
164  166                            York Preparatory School  40.774100 -73.979400
165  167                    Young Women's Leadership School  40.792900 -73.947200
166  168   Washington Heights Expeditionary Learning School  40.774100 -73.979400

Upvotes: 3

Related Questions