Monday, October 12, 2020

Python and Openpyxl - Read in multiple txt files and store as different worksheets in a single Excel file

If you have some text file and want to combine them into different worksheets of the same Excel file, simply follow the example below using Python:

1. Create some txt files and separate data with tabs:


2. Save the following code as a python file:

import csv
import openpyxl

inputArray = ['a', 'b', 'c']

wb = openpyxl.Workbook()
output_file = 'output.xlsx'

#loop in the reversed order so that the first file is stored as the first sheet.
for item in reversed(inputArray):

    input_file = item+'.txt'
    sheet = wb.create_sheet(item, 0)

    with open(input_file, 'rt') as data:
    reader = csv.reader(data, delimiter='\t')
    for row in reader:
    sheet.append(row)

wb.save(output_file)

Note: install openpyxl using pip or miniconda if required.

3. result:



Reference:

如何使用 Python 程式操作 Excel 試算表 (TechBridge 技術共筆部落格 by kdchang)

Friday, October 9, 2020

Raspberry - Pronunciation 什麼!? 樹莓派的英文發音竟然跟你想的不一樣?

你接觸樹莓派(Raspberry Pi)多久了呢?

「樹莓」的英文字Raspberry看起來不難發音吧... 你也是唸Rasp+Berry嗎?

其實,跟想像的不一樣喔!竟然是:


p不發音!p不發音!p不發音!(很重要所以說三次!)


所以唸起來比較像是Raz-berry

記起來了嗎?


發音聽這邊:

How to say raspberry (Cambridge Dictionary YouTube) (包括英式與美式發音)

這30個台灣人常唸錯的英文字😲 你答對幾個? (Lily Chen YouTube 6:00)