You should show how you are importing the data to help answer the question.
I would recommend parsing this data into an actual csv format before reading into pandas:
12345S
Item 1
4152DS
Item 2
15190A
Item 3
To this:
AN,Artikel
12345S,Item 1
4152DS,Item 2
15190A,Item 3
Which will be read by pandas cleaner.You should show how you are importing the data to help answer the question.
Which will be read by pandas cleaner.
Edit: To import and sort:
I would recommend parsing this data into an actual csv format before reading into pandas:
import csv headers = ['AN', 'Artikel'] with open('data.txt', 'r') as in_data, open('out.csv', 'w', newline='') as out_csv: csv_writer = csv.writer(out_csv) i = 0 row = [] csv_writer.writerow(headers) # make sure your data ends in a new line or you won't import the last line for line in in_data.readlines(): if i % 2 == 0 and i != 0: csv_writer.writerow(row) row.clear() i += 1 row.append(line.strip()) csv_writer.writerow(row) row.clear()This converts this:
12345S
Item 1
4152DS
Item 2
15190A
Item 3
To this:
AN,Artikel
12345S,Item 1
4152DS,Item 2
15190A,Item 3
Which will be read by pandas cleaner.You should show how you are importing the data to help answer the question.
Which will be read by pandas cleaner.
Edit: To import and sort:
import pandas as pd df = pd.read_csv('out.csv') df.sort_values(["AN"], inplace=True) print(df.head())Output:
AN Artikel 0 12345S Item 1 2 15190A Item 3 1 4152DS Item 2