【发布时间】:2022-01-21 22:45:13
【问题描述】:
我有这样的数据:
ID 1
x y
3 4
4 3
6 8
ID 2
x y
3 4
4 3
6 8
.
.
.
ID 100
x y
2 40
41 32
6 8
我想为每个 ID 创建一个数据文件,例如 ID_1.txt、ID_2.txt... 我的代码是:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
###############################################
fichier = "data.txt"
file = open(fichier).read().split('\n')
n =0
j=0
id=[]
for i in file :
# print("********",i)
current_id = j+1
if 'ID' in i:
id.append(n+1)
print('n=',n)
globals()[f'ID_{n}']=[]
n+=1
while current_id == id[-1] :
if i.find('ID'):
print(i.find('ID'))
eval()[f'ID_{n}'].append(i)
我仍然得到一个空的 ID_{n} 列表,知道吗?
谢谢。
【问题讨论】:
标签: python list dataframe readline