【发布时间】:2018-12-21 06:49:17
【问题描述】:
我有以下通过 pandas 读取的数据输入。
我想将单元格“月末.....”放入新形成的“日期”列,并将两个输入文件一起附加到一个数据帧中。
这是我迄今为止尝试过的......
import pandas as pd
import glob
import os
### List Source Files That I need to Import###
path = os.getcwd()
files = os.listdir(path)
### Loading Files by Variable ###
data = pd.DataFrame()
for files in glob.glob('../Sales_Master_Data/Sales_Data/* customer *.xls'): #searches for customer .xls files in the folder
data = pd.read_excel(files,'sheet1',skiprows=0).fillna(method='ffill')#reads all files in df
date = data.columns[4] # This is where the date value is located
data['Date'] = date # Assigns date value to new ['Date'] column
df = df.append(data) # all files are appended together
df.to_csv('Output.csv')
不幸的是,它产生了下面的输出。所有以 'Month' 开头的列都需要合并到 1 列并称为 ['Sales Qty'] 我也无法整理列标题以使其统一
【问题讨论】:
-
将单元格放入新列是什么意思?
-
我想从单元格中获取值 ('Month Ending .....') ,创建一个名为 'Date' 的列并将 Date 中的值作为一行存储
-
您能否包含您的“打印(数据)”语句的输出?
-
我已更新以使其更清晰@Gerardo Flores