Reputation: 349
I have a text file that looks like this,
data = '''1|b|c
2|e|f|g|h|i|j|k
2|2|3|4|5|6|7|8
1|e|f'''
I want to use pandas to create multiple tables from the data.
What is the recommended fast & easy way to get this done using pandas ?
Upvotes: 0
Views: 1550
Reputation: 4265
You can just set delimiter on pandas
read, as in:
# Or .read_table
master_table = pd.read_csv("file.txt", delimter="|")
# Select just the rows where an arbitrary column is 1.
df1 = master_table[master_table["column_name"] == 1].copy()
Perhaps it is simpler to iterate through the file:
with open("file.txt", "r") as file:
for line in file:
if line[0] == 1: # Check any arbitrary condition
# Process the data
Upvotes: 1