Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
2317 มุมมอง

How can I create a custom import button that take a .txt file and manipulate it using the pandas library and insert the records into a model.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

In this example, the fields in the text file are separated by the user-defined delimiter “/”.

# importing pandas library
import pandas as pd
 
# reading the given csv file
# and creating dataframe
data = pd.read_csv("file.txt", delimiter = '/')
 
# store dataframe into csv file
data.to_csv('file.csv', index = None)

for more info you can refer other examples in the text file contents alignments

# import csv files

csv_data = base64.b64decode(data)

data_file = io.StringIO(csv_data.decode("utf-8"))

csv_reader = csv.reader(data_file, delimiter=',')

In the above code the data will be in csv_reader you can use the data into your requirements

Regards

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
มิ.ย. 20
4014
1
พ.ย. 18
9487
11
ก.พ. 17
63789
Import contacts through CSV แก้ไขแล้ว
2
มี.ค. 15
10960
4
พ.ย. 24
11296