Untitled

 avatar
unknown
plain_text
a year ago
780 B
6
Indexable
import pandas as pd

# Bước 1: Đọc dữ liệu từ file text
input_file = 'input.txt'
data = []
with open(input_file, 'r', encoding='utf-8') as file:
    for line in file:
        # Bỏ qua dòng trống và dòng không phải dữ liệu
        if '|' in line:
            columns = line.strip().split('|')
            # Loại bỏ khoảng trắng thừa ở đầu và cuối mỗi phần tử
            data.append([col.strip() for col in columns])

# Bước 2: Chuyển đổi dữ liệu thành DataFrame của pandas
df = pd.DataFrame(data, columns=['Họ', 'Tên'])

# Bước 3: Ghi DataFrame ra file Excel
output_file = 'output.xlsx'
df.to_excel(output_file, index=False, engine='openpyxl')

print(f'Dữ liệu đã được ghi vào file {output_file}')
Editor is loading...
Leave a Comment