I am following an online Python course, which is getting into data frames.
I downloaded this CSV file and imported it into a data frame:
import os
import pandas as pd
os.chdir('C:/cygwin64/home/User.Name/path/to/brics.csv')
pd.read_csv( os.getcwd() + '/brics.csv' )
myBrics = pd.read_csv( 'brics.csv' )
myBrics
Unnamed: 0 country capital area population
0 BR Brazil Brasilia 8.516 200.40
1 RU Russia Moscow 17.100 143.50
2 IN India New Delhi 3.286 1252.00
3 CH China Beijing 9.597 1357.00
4 SA South Africa Pretoria 1.221 52.98
I then used the code given in the course presentation to create the same data frame
dict = {
"country":["Brazil", "Russia", "India", "China", "South Africa"],
"capital":["Brasilia", "Moscow", "New Delhi", "Beijing", "Pretoria"],
"area":[8.516, 17.10, 3.286, 9.597, 1.221],
"population":[200.4, 143.5, 1252, 1357, 52.98] }
brics = pd.DataFrame(dict)
brics
country capital area population
0 Brazil Brasilia 8.516 200.40
1 Russia Moscow 17.100 143.50
2 India New Delhi 3.286 1252.00
3 China Beijing 9.597 1357.00
4 South Africa Pretoria 1.221 52.98
They appear to be identical except that for the first column in myBrics
. Some web searching showed that I can get rid of column 1:
myBrics.drop( myBrics.columns[[0]] , axis=1 )
country capital area population
0 Brazil Brasilia 8.516 200.40
1 Russia Moscow 17.100 143.50
2 India New Delhi 3.286 1252.00
3 China Beijing 9.597 1357.00
4 South Africa Pretoria 1.221 52.98
However, the identical looking data frames are still not equal:
myBrics.drop( myBrics.columns[[0]] , axis=1 ).equals( brics )
False
Can anyone please explain what is going on? Thanks.
I am using Python 3.7 from Spyder, installed (by someone with administrator rights) via Anaconda. The OS is Windows 7 64-bit.