我的.csv文件中出现一个额外的列

时间:2019-06-04 09:53:43

标签: python python-3.x pandas csv

我有一个名为export .py的文件,代码如下(我正在学习如何使用熊猫)

import pandas as pd

dict = {"country": ["Brazil", "Russia", "India", "China", "South Africa"],
       "capital": ["Brasilia", "Moscow", "New Dehli", "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.index = ["BR", "RU", "IN", "CH", "SA"]
print(brics)
print()
print()
print("Exporting as .csv file...")
export_csv = brics.to_csv ('/some/path/to/file/panda.csv', index=True, header=True)
print("Done!")

和另一个文件import.py:

import pandas as pd
brics = pd.read_csv("/path/to/file/panda.csv")
print(brics)

的输出是:

#export.py
         country    capital    area  population
BR        Brazil   Brasilia   8.516      200.40
RU        Russia     Moscow  17.100      143.50
IN         India  New Dehli   3.286     1252.00
CH         China    Beijing   9.597     1357.00
SA  South Africa   Pretoria   1.221       52.98


Exporting as .csv file...
Done!

#import.py
  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 Dehli   3.286     1252.00
3         CH         China    Beijing   9.597     1357.00
4         SA  South Africa   Pretoria   1.221       52.98

谁能告诉我如何清理表,使两个输出看起来相同(删除“ 0、1、2、3 ...”索引)?

0 个答案:

没有答案