Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
2341 Переглядів

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
4026
1
лист. 18
9497
11
лют. 17
63808
2
бер. 15
10971
4
лист. 24
11315