如何摆脱行号,pd.read_excel?

kst*_*ich 5 python excel pandas

我是一个完全的 Python 初学者。我正在做一项作业在使用import pandas.

这是我运行代码时得到的结果:

0   $20,000,000 $159,000,000  
1    $9,900,000  $35,600,000  
2   $35,000,000  $45,000,000  
3    $9,900,000  $35,600,000  
4   $12,000,000   $9,400,000 
Run Code Online (Sandbox Code Playgroud)

但我只想:

$20,000,000  $159,000,000  
$9,900,000   $35,600,000  
$35,000,000  $45,000,000  
$9,900,000   $35,600,000  
$12,000,000  $9,400,000 
Run Code Online (Sandbox Code Playgroud)

这是我的主要格式化块的内部:

if __name__ == "__main__":
    file_name = "movie_theme.xlsx"    

    # Formatting numbers (e.g. $1,000,000)
    pd.options.display.float_format = '${:,.0f}'.format

    # Reading Excel file
    df = pd.read_excel(file_name, convert_float = False)
Run Code Online (Sandbox Code Playgroud)

关于如何去做这件事有什么建议吗?

Har*_*nna 1

你可以试试

df = df.set_index('Salary')
Run Code Online (Sandbox Code Playgroud)

其中Salary是您想要作为索引的列名。

行号称为索引。