Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
2307 Näkymät

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.

Avatar
Hylkää
Paras vastaus

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

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
3
kesäk. 20
4012
1
marrask. 18
9486
11
helmik. 17
63783
2
maalisk. 15
10957
4
marrask. 24
11293