Here is my csv file
Country 2010 2011 2012 2013 2014
Albania 5.5 19.1 6.9 15.4 8
Algeria 18.2 6 8.1 20 9.5
American Samoa 14.1 13.8 3 14.7 2.3
Andorra 16 3 13.6 12.4 8.3
Angola 17.8 9.8 8.8 6.5 5.5
my code:
import pandas as pd
test = pd.read_csv('C:\\Users\\Wing\\Desktop\\TEST.csv',sep='\t')
print(test.head())
print(test.shape)
print(test.columns)
print(test.dtypes)
output:
the print test.shape command will output (14,1)
the print test.columns command will output(Index(['Country,2010,2011,2012,2013,2014'], dtype='object')
so how can I separate them to 6 columns
Your csv file seems fine:
In [ ]: from io import StringIO
...: import pandas as pd
...: TESTDATA = StringIO("""Country 2010 2011 2012 2013 2014
...: Albania 5.5 19.1 6.9 15.4 8
...: Algeria 18.2 6 8.1 20 9.5
...: American Samoa 14.1 13.8 3 14.7 2.3
...: Andorra 16 3 13.6 12.4 8.3
...: Angola 17.8 9.8 8.8 6.5 5.5""")
...: test = pd.read_csv(TESTDATA,sep='\t')
...: print(test)
Country 2010 2011 2012 2013 2014
0 Albania 5.5 19.1 6.9 15.4 8
1 Algeria 18.2 6 8.1 20 ...
2 American Samoa 14.1 13.8 3 14.7 ...
3 Andorra 16 3 13.6 12.4 ...
4 Angola 17.8 9.8 8.8 6.5 ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.