Bazman
Bazman

Reputation: 2150

Pandas read_csv appending a row of Nan values

Why do the code snippets produce a row of NaN's on the bottom row?

In both cases the rest of the rows are all fine it's just that a row of nan's are appended at the end.

pd.read_csv("http://www.football-data.co.uk/mmz4281/1516/E2.csv")
pd.read_csv("http://www.football-data.co.uk/mmz4281/1516/E3.csv")

I have also read in every other file of that site and these are the only ones where this happens? See for example the code snippet below which does not produce any Nan's at the end.

pd.read_csv("http://www.football-data.co.uk/mmz4281/1516/E0.csv")

I have looked online for a solution but can't seem to find a problem quite like this.

Upvotes: 1

Views: 770

Answers (1)

yosukesabai
yosukesabai

Reputation: 6244

The file has empty row at the end, so you have to strip it by yourself. Last two lines of E2.csv file shown below.

E2,08/05/16,Wigan,Barnsley,1,4,A,1,2,A,T Harrington,8,10,4,7,11,6,4,3,1,1,1,0,2.38,3.6,3.1,2.2,3.3,2.9,2.25,3.25,2.8,2.3,3.4,2.9,2.42,3.53,3.04,2.3,3.3,3.1,2.38,3.6,2.9,45,2.42,2.32,3.6,3.36,3.1,2.91,38,1.87,1.77,2.09,2,27,-0.25,2.08,2.01,1.87,1.82,2.32,3.85,2.99
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

Upvotes: 1

Related Questions