我一直在为考古学课程介绍数据科学,目前正为第一件(未标记)的作品而苦苦挣扎。虽然我了解了我打算编写的代码的整体逻辑,并且在用psudocode编写代码时没有遇到问题,但我在语法方面仍处很多麻烦。我已经向我的讲师寻求帮助/建议,但是我的讲师并不擅长解释语法。抱歉,这是超级基础-我对编程很陌生。
我想做的是打开目录中的每个CSV文件,为其创建一个唯一命名的对象,将来自CSV文件中特定单元格的数据存储在该对象中。
我已经在另一个模块中定义了对象(Table
)的类,并将其导入。我还定义了目录路径。我不能用熊猫做这项工作。
到目前为止,我编写的唯一真正相关的实际代码是:
import os
import csv
from table import Table
from analysis import Analysis
src_folder = os.path.dirname(os.path.realpath(__file__))
data_folder = os.path.join(src_folder,test_data")
os.chdir(data_folder)
for infile in os.listdir(data_folder):
if infile.endswith('.csv'):
# to check if working,delete from final
print "Current File Being Processed is: " + infile
# define object as instance of Table()
with open(infile) as csvfile:
reader = csv.reader(csvfile)
# skips the header row
next(reader,None)
for row in reader:
# prints fourth column to make sure its actually reading data
print(row[3])
我在这里要做的是为每个具有唯一名称的文件自动创建一个Table()
对象。我还希望能够从CSV文件中的特定单元格而不是整个行中定义两个值(self.beta
和self.alpha
)。有办法做到这两种方法吗?