-3

i cant seems to remove the unnamed and also the serial number from the csv file. i've look online it says using index_col = 0. but still not working.

Is there any other way doing it?

Code is :
brics = pd.read_csv('brics.csv', index_col = 0)

and the csv output is :

 Unnamed: 0.1 country capital area population
0 BR Brazil Brasilia 8.516 200.40
1 RU Russia Moscow 17.100 143.50
3 CH China Beijing  9.597 1357.00
4 SA South_Africa Pretoria 1.221 52.98

What i need to to remove the unnamed:0.1 and also the serial number

Thanks

Thanks

enter image description here

oce priatna
  • 21
  • 1
  • 1
  • 3

2 Answers2

0

What you call a "serial number" is the index of your dataframe (dataframe is your object type - pandas.DataFrame) so you cannot remove it. Read more about removing the index in that SO Post: Removing index column in pandas

to remove your unnamend column try:

brics = pd.read_csv('brics.csv', index_col = 0)  
brics =brics.drop(columns=['Unnamend: 0.1'])
brics
Florian H
  • 3,052
  • 2
  • 14
  • 25
0

use if you really want no index to be printed:

brics.drop(['Unnamed:0.1'],axis=1,inplace=True)
print (brics.to_string(index=False))

if you don't want to loose the data in the unnamed column, simply rename it:

brics.rename(columns={'Unnamed:0.1':'something'},inplace = True)

if you want this to be your axis, add the below line after you rename the column:

brics.set_index('something')

post this you can call the print function.

Hope this helps!

anky
  • 74,114
  • 11
  • 41
  • 70