Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从表中删除索引_Python_Pandas - Fatal编程技术网

Python 从表中删除索引

Python 从表中删除索引,python,pandas,Python,Pandas,我正在使用pandas导入包含股票数据的csv文件。似乎每次我保存文件时,Pandas都会向文件中添加一行id为的行 import yfinance as yf import pandas as pd #Open File df = pd.read_csv('balance.csv') #Calculating Current Value df['Value'] = df['BuyPrice'] * df['BuyAmount'] #Adding Most Recent Price to

我正在使用pandas导入包含股票数据的csv文件。似乎每次我保存文件时,Pandas都会向文件中添加一行id为的行

import yfinance as yf
import pandas as pd

#Open File
df = pd.read_csv('balance.csv')

#Calculating Current Value
df['Value'] = df['BuyPrice'] * df['BuyAmount']

#Adding Most Recent Price to CSV File
ticker_stock = yf.Ticker('AAPL')
data = ticker_stock.history()
df['Price'] = (data.tail(1)['Close'].iloc[0])
print(df)

#Save File
df.to_csv('balance.csv')
如果我运行程序3次,我将有3行带有ID。有没有办法阻止pandas在每次保存时向我显示行id并将其添加到文件中?
id似乎也阻止了我使用表中的数据进行统计,因为每次我从表中提取数据时,它都包含id。

第一步是读取帮助/文档:。只需使用
index=False
。这对保存表有效。我也可以在read_csv上使用它吗?我不想在打印文档时看到索引table@Louis也许这有助于@Louis-您在
[read\u csv]中有几个选项(https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html#pandas-阅读csv)索引_col=0`将使用列0作为索引。如果您知道应该存在的列数,比如3,
usecols=[1,2,3]
将跳过零列索引。如果您有一些文件具有索引,而一些文件由于之前的
而没有索引,则第一列将没有标签。如果df:df.drop(columns=[“Unamed:0”],inplace=True)中的“Unamed:0”,则可以执行