用Python编写excel文件

用Python编写excel文件,python,excel,Python,Excel,几天前,我发布了这个问题的一部分,并给出了一个很好的答案,但这只是解决了我问题的一部分。 因此,我有一个excel文件,需要对其进行一些数据挖掘,然后需要拿出另一个格式相同的excel文件.xlsx 问题是,我在编写文件后得到一个奇怪的列,在使用Anaconda编写之前无法看到该列。这使得我们更难制定一个策略来对抗它的外表。起初我认为通过将宽度减小到0解决了这个问题,但显然在某个时候文件需要转换为文本,然后列重新出现。 有关更多详细信息,请参见我的部分代码: import os import p

几天前,我发布了这个问题的一部分,并给出了一个很好的答案,但这只是解决了我问题的一部分。 因此,我有一个excel文件,需要对其进行一些数据挖掘,然后需要拿出另一个格式相同的excel文件.xlsx 问题是,我在编写文件后得到一个奇怪的列,在使用Anaconda编写之前无法看到该列。这使得我们更难制定一个策略来对抗它的外表。起初我认为通过将宽度减小到0解决了这个问题,但显然在某个时候文件需要转换为文本,然后列重新出现。 有关更多详细信息,请参见我的部分代码:

import os
import pandas as pd
import numpy as np
import xlsxwriter

# Retrieve current working directory (`cwd`)
cwd = os.getcwd()
cwd

# Change directory 
os.chdir("/Users/s7c/Documents/partsstop")

# Assign spreadsheet filename to `file`
file = 'file = 'SC daily inventory retrieval columns for reports'.xlsx

# Load spreadsheet
xl = pd.ExcelFile(file)

# Load a sheet into a DataFrame by name: df
df = xl.parse('Sheet1')

#second file code:
#select just the columns we need and rename them:
df2 = df.iloc[:, [1, 3, 6, 9]]
df2.columns = ['Manufacturer Code', 'Part Number', 'Qty Available', 'List Price']

#then select just the rows we need:
df21 = df2[df2['Manufacturer Code'].str.contains("DRP")]#13837 entries

#select just the DRP, first 3 characters and dropping the ones after:
df21['Manufacturer Code'] = df21['Manufacturer Code'].str[:3]

#add a new column:
#in order to do that we need to convert the next column to numeric:
df21['List Price'] = pd.to_numeric(df21['List Price'], errors='coerce')
df21['Dealer Price']  = df21['List Price'].apply(lambda x: x*0.48) #new column equals half of other column
writer = pd.ExcelWriter('example2.xlsx', engine='xlsxwriter')

# Write your DataFrames to a file     
df21.to_excel(writer, 'Sheet1')
对问题的实际看法:


任何建设性的想法都将受到赞赏。谢谢

此列似乎是数据帧的索引。您可以通过向传递
index=False
来排除它