我一般都是python / scripting的新手。需要有关如何解决问题的指导。我有以下python代码,可以在我的Mac上工作,但不是当我切换到Windows时。
create_data_frame.py
#!/usr/bin/env python
from argparse import ArgumentParser
from data_frame import DataFrame
from display_statistics import DisplayStatistics
from pprint import pprint
def main():
# cli args
parser = ArgumentParser()
parser.add_argument(
'-v', '--verbose',
help='More verbose output',
action='store_true',
default=False,
)
"""
parser.add_argument('-t', '--datatype',
help = 'what is the data type: csv, excel, webpage?',
required=True )
"""
parser.add_argument(
'-r', '--rootpath',
help='root path',
required=True
)
parser.add_argument(
'-p', '--pattern',
help='pattern to look for',
required=True,
)
args = parser.parse_args()
df1 = DataFrame(
root_path=args.rootpath,
pattern=args.pattern,
)
df2 = DisplayStatistics(root_path=args.rootpath,
pattern=args.pattern,
)
print 'From data_frame'
df1.data_frame()
df1.summary_stats()
print 'From display_statistics'
#df2.data_frame()
#df2.get_dict()
#print df2.summary_stats()
#print df2.box_plot()
#print df2.cross_tab()
if __name__ == '__main__':
main()
data_frame.py
# !/usr/bin/env python
from os import path, walk
from fnmatch import filter
import pandas as pd
class DataFrame(object):
def __init__(self, root_path, pattern):
self.root_path = root_path
self.pattern = pattern
self.rf_list = [] # create empty list to store ReaderAnalysis.csv locations
self.all_readerfiles = []
self.frame = pd.DataFrame()
def get_dict(self):
return {
'root_path': self.root_path,
'pattern': self.pattern,
'rf_list': self.rf_list,
'all_readerfiles': self.all_readerfiles,
'frame': self.frame
}
def data_frame(self):
for root, dirs, files in walk(self.root_path):
for filename in filter(files, self.pattern):
self.rf_list.append(path.join(root, filename))
for readerfiles in self.rf_list:
df = pd.read_csv(readerfiles)
df["Sample_IDs"] = ['Control 1','Control 2','Control 3','Control 1','Control 2','Control 3']
df['RunID'] = readerfiles[readerfiles.find("_RunID") + 1:readerfiles.find("/ReaderFiles")]
df['Instrument'] = readerfiles[readerfiles.find("Data/") + 5:readerfiles.find("_")]
self.all_readerfiles.append(df)
self.frame = pd.concat(self.all_readerfiles)
def summary_stats(self):
class_type = type(self.frame)
dim = self.frame.shape
first_6 = self.frame.head(6)
last_6 = self.frame.tail(6)
describe = self.frame.describe()
return [class_type, dim,describe]
我收到以下错误:
Traceback (most recent call last):
File "create_data_frame.py", line 67, in <module>
main()
File "create_data_frame.py", line 50, in main
df1.data_frame()
File "D:\ControlTracking\create_data_frame\data_frame.py", line 37, in data_frame
self.frame = pd.concat(self.all_readerfiles)
File "C:\Python27\lib\site-packages\pandas\core\reshape\concat.py", line 206, in concat
copy=copy)
File "C:\Python27\lib\site-packages\pandas\core\reshape\concat.py", line 239, in __init__
raise ValueError('No objects to concatenate')
ValueError: No objects to concatenate
我在我的Mac上运行相同的代码并且工作正常。我有什么明显的差异吗?我可能在设置环境时犯了错误,但我该如何检查。