我正在从文件夹中读取csv
文件,并将tem过滤到pandas
数据帧中,如下所示:
results=[]
for filename in glob.glob(os.path.join('/path/*.csv')):
with open(filename) as p:
df = pd.read_csv(p)
filtered = df[(df['duration'] > low1) & (df['duration'] < high1)]
artist = filtered['artist'].values
print artist
track = filtered['track'].values
print track
其中low1 = 0
,high_1 = 0.5
artist
和track
将数百个过滤后的项目作为普通字符串打印出来,但是如果我尝试将它们附加到循环中的results
中:
{I>和填充了 如何用常规的results
填充results
,以这种方式:[['artist1', 'track1'], ['artist1', 'track2], ...]]
创建} 将它们连接在一起,最后转换为嵌套列表:
DataFrame
的列表,然后通过^{另一个解决方案id追加列表,最后通过列表理解将其展平:
^{pr2}$相关问题 更多 >
编程相关推荐