예제 #1
0
파일: base.py 프로젝트: jnothman/pyexcel
 def test_reading_through_sheets(self):
     b = pe.BookReader(self.testfile)
     data = pe.utils.to_array(b["Sheet1"].rows())
     expected = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]
     assert data == expected
     data = pe.to_array(b["Sheet2"].rows())
     expected = [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]
     assert data == expected
     data = pe.to_array(b["Sheet3"].rows())
     expected = [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]
     assert data == expected
     sheet3 = b["Sheet3"]
     s3 = sheet3.become_series()
     data = pe.to_array(s3.rows())
     expected = [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
     assert data == expected
예제 #2
0
 def test_reading_through_sheets(self):
     b = pe.BookReader(self.testfile)
     data = pe.utils.to_array(b["Sheet1"].rows())
     expected = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]
     assert data == expected
     data = pe.to_array(b["Sheet2"].rows())
     expected = [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]
     assert data == expected
     data = pe.to_array(b["Sheet3"].rows())
     expected = [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]
     assert data == expected
     sheet3 = b["Sheet3"]
     sheet3.name_columns_by_row(0)
     data = pe.to_array(sheet3.rows())
     expected = [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
     assert data == expected
예제 #3
0
 def test_empty_series_reader(self):
     # debug this further
     s = pe.Sheet()  # seriesreader is gone since v0.0.7
     assert s.name == "pyexcel"
     test_data = [[1, 2, 3], [4, 5, 6], ["Column 1", "Column 2", "Column 3"]]
     s.column += pe.transpose(test_data)
     actual = pe.to_array(s)
     assert test_data == actual
     s.name_columns_by_row(2)
     assert s.colnames == test_data[2]
예제 #4
0
 def test_empty_series_reader(self):
     # debug this further
     s = pe.Sheet()  # seriesreader is gone since v0.0.7
     assert s.name == "pyexcel sheet"
     test_data = [[1, 2, 3], [4, 5, 6],
                  ["Column 1", "Column 2", "Column 3"]]
     s.column += pe.transpose(test_data)
     actual = pe.to_array(s)
     assert test_data == actual
     s.name_columns_by_row(2)
     assert s.colnames == test_data[2]
예제 #5
0
파일: views.py 프로젝트: CometHale/AMS30
def input_from_excel():
	input_sheet = excel.get_sheet(file_name="supers_data.xlsx", name_columns_by_row=0)
	records = excel.to_array(input_sheet.rows())
	for record in records:
		if not irl_city_exist(record[3]) and record[5] != '' and record[6] != '':
			new_irl_city = IRLCity.objects.create(name=record[3], province=record[4], latitude=record[5] , longitude=record[6])
			new_irl_city.save()
		if not universe_exist(record[2]):
			new_bang = Universe.objects.create(company_name=record[2], origin_country=record[8])
			new_bang.save()
		if not super_exist(record[0]):
			if record[3] != '':
				city = IRLCity.objects.get(name=record[3])
				universe = Universe.objects.get(company_name=record[2])
				new_super = Super.objects.create(name=record[0],identity=record[7],origin_city=record[1],irl_city=city, company_universe=universe)
				new_super.save()
예제 #6
0
파일: series.py 프로젝트: jayvdb/pyexcel
def main(base_dir):
    # print all in json
    #
    # Column 1 Column 2 Column 3
    # 1        4        7
    # 2        5        8
    # 3        6        9
    sheet = pe.load(os.path.join(base_dir, "example_series.ods"),
                    name_columns_by_row=0)
    print(json.dumps(sheet.to_dict()))
    # output:
    # {"Column 2": [4.0, 5.0, 6.0], "Column 3": [7.0, 8.0, 9.0], "Column 1": [1.0, 2.0, 3.0]}

    # get the column headers
    print(sheet.colnames)
    # [u'Column 1', u'Column 2', u'Column 3']

    # get the content in one dimensional array
    data = pe.to_array(sheet.enumerate())
    print(data)
    # [1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0]

    # get the content in one dimensional array
    # in reverse order
    data = pe.to_array(sheet.reverse())
    print(data)

    # get the content in one dimensional array
    # but iterate it vertically
    data = pe.to_array(sheet.vertical())
    print(data)
    # [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]

    # get the content in one dimensional array
    # but iterate it vertically in revserse
    # order
    data = pe.to_array(sheet.rvertical())
    print(data)
    #[9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0]

    # get a two dimensional array
    data = pe.to_array(sheet.rows())
    print(data)
    #[[1.0, 4.0, 7.0], [2.0, 5.0, 8.0], [3.0, 6.0, 9.0]]

    # get a two dimensional array in reverse
    # order
    data = pe.to_array(sheet.rrows())
    print(data)
    # [[3.0, 6.0, 9.0], [2.0, 5.0, 8.0], [1.0, 4.0, 7.0]]

    # get a two dimensional array but stack columns
    data = pe.to_array(sheet.columns())
    print(data)
    # [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]

    # get a two dimensional array but stack columns
    # in reverse order
    data = pe.to_array(sheet.rcolumns())
    print(data)
    #[[7.0, 8.0, 9.0], [4.0, 5.0, 6.0], [1.0, 2.0, 3.0]]

    # filter out odd rows and even columns
    sheet.filter(pe.OddRowFilter())
    sheet.filter(pe.EvenColumnFilter())
    data = sheet.to_dict()
    print(data)
    # {u'Column 3': [8.0], u'Column 1': [2.0]}

    # and you can write the filtered results
    # into a file
    sheet.save_as("example_series_filter.xls")
예제 #7
0
# 	for i in tweet:
# 		print i
# 	print "\n"

trainclf = SVC(kernel='rbf', gamma=0.5)

sc = 0
fulltext = []
fullutext = []
fulltag = []
book = pyexcel.get_book(file_name="English_Train-final.xlsx")
for sheet in book:
    if sc == 3:
        break

    data = pyexcel.to_array(sheet.rows())
    text = []
    utext = []
    tag = []
    for tweet in data:
        tx = tweet[0]
        tx = clean(tx)
        utext.append(tweet[0])
        text.append(tx)
        tag.append(tweet[1])
        fullutext.append(tweet[0])
        fulltext.append(tx)
        fulltag.append(tweet[1])

    # for i,r in df.iterrows():
    # 	tx=r['text']
예제 #8
0
def main(base_dir):
    # print all in json
    #
    # Column 1 Column 2 Column 3
    # 1        4        7
    # 2        5        8
    # 3        6        9
    sheet = pe.get_sheet(file_name=os.path.join(base_dir,
                                                "example_series.ods"),
                         name_columns_by_row=0)
    print(json.dumps(sheet.to_dict()))
    # output:
    # {"Column 2": [4.0, 5.0, 6.0], "Column 3": [7.0, 8.0, 9.0],
    #  "Column 1": [1.0, 2.0, 3.0]}

    # get the column headers
    print(sheet.colnames)
    # [u'Column 1', u'Column 2', u'Column 3']

    # get the content in one dimensional array
    data = pe.to_array(sheet.enumerate())
    print(data)
    # [1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0]

    # get the content in one dimensional array
    # in reverse order
    data = pe.to_array(sheet.reverse())
    print(data)

    # get the content in one dimensional array
    # but iterate it vertically
    data = pe.to_array(sheet.vertical())
    print(data)
    # [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]

    # get the content in one dimensional array
    # but iterate it vertically in revserse
    # order
    data = pe.to_array(sheet.rvertical())
    print(data)
    # [9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0]

    # get a two dimensional array
    data = pe.to_array(sheet.rows())
    print(data)
    # [[1.0, 4.0, 7.0], [2.0, 5.0, 8.0], [3.0, 6.0, 9.0]]

    # get a two dimensional array in reverse
    # order
    data = pe.to_array(sheet.rrows())
    print(data)
    # [[3.0, 6.0, 9.0], [2.0, 5.0, 8.0], [1.0, 4.0, 7.0]]

    # get a two dimensional array but stack columns
    data = pe.to_array(sheet.columns())
    print(data)
    # [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]

    # get a two dimensional array but stack columns
    # in reverse order
    data = pe.to_array(sheet.rcolumns())
    print(data)
    # [[7.0, 8.0, 9.0], [4.0, 5.0, 6.0], [1.0, 2.0, 3.0]]

    # filter out odd rows and even columns
    sheet.filter(pe.OddRowFilter())
    sheet.filter(pe.EvenColumnFilter())
    data = sheet.to_dict()
    print(data)
    # {u'Column 3': [8.0], u'Column 1': [2.0]}

    # and you can write the filtered results
    # into a file
    sheet.save_as("example_series_filter.xls")
예제 #9
0
	return p

def lastex(sent):
	# print("out ex")
	return sent[len(sent)-1]=='!'

def lastq(sent):
	# print("out q")
	return sent[len(sent)-1]=='?'


book = pyexcel.get_book(file_name="English_Train-final.xlsx")
for sheet in book:
	text=[]
	tag=[]
	data=pyexcel.to_array(sheet.rows())

	for tweet in data:
		tx=tweet[0]
		tx=clean(tx)
		text.append(tx)
		if(tweet[1]==2):
			tag.append(tweet[2])
		tag.append(tweet[1])

	textlist=[]
	c=0
	for sent in text:
		# textlist.append([has_modal(s),has_strong(s),has_personal(s),has_long(s), has_wh(s)])
		textlist.append([has_long(sent), checknegation(sent), getnrcscore(sent),getemoscore(sent),
			counthashtags(sent), countupper(sent), lastex(sent), lastq(sent),gets140_bi(sent),gets140_uni(sent),gets140_an_bi(sent), gets140_an_uni(sent)])
예제 #10
0
파일: series.py 프로젝트: bdeeney/pyexcel
#
# Column 1 Column 2 Column 3
# 1        4        7
# 2        5        8
# 3        6        9
sheet = pe.load("example_series.ods", name_colmns_by_row=0)
print json.dumps(sheet.to_dict())
# output:
# {"Column 2": [4.0, 5.0, 6.0], "Column 3": [7.0, 8.0, 9.0], "Column 1": [1.0, 2.0, 3.0]}

# get the column headers
print sheet.colnames()
# [u'Column 1', u'Column 2', u'Column 3']

# get the content in one dimensional array
data = pe.to_array(sheet.enumerate())
print data
# [1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0]

# get the content in one dimensional array
# in reverse order
data = pe.to_array(sheet.reverse())
print data

# get the content in one dimensional array
# but iterate it vertically 
data = pe.to_array(sheet.vertical())
print data
# [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]

# get the content in one dimensional array