read_csv doesn't read the column names correctly on this file?
Add parameter sep="\s+"
or delim_whitespace=True
to read_csv
:
import pandas as pd
temp=u"""0 5
1 10
2 15
3 20
4 25"""
#after testing replace io.StringIO(temp) to filename
column_names = ['x','y']
df = pd.read_csv(pd.compat.StringIO(temp), sep="\s+", header = None, names = column_names)
print (df)
x y
0 0 5
1 1 10
2 2 15
3 3 20
4 4 25
Or:
column_names = ['x','y']
df = pd.read_csv(pd.compat.StringIO(temp),
delim_whitespace=True,
header = None,
names = column_names)
print (df)
x y
0 0 5
1 1 10
2 2 15
3 3 20
4 4 25
You could try this :
import pandas as pd
column_names = ['x','y']
df = pd.read_csv('csv-file.csv',header=None)
df.columns = column_names