콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
2313 화면

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

아바타
취소
관련 게시물 답글 화면 활동
3
6월 20
4013
1
11월 18
9486
11
2월 17
63785
2
3월 15
10958
4
11월 24
11294