【发布时间】:2018-02-08 03:18:25
【问题描述】:
我有点困惑,因为以下似乎可行:
raw_data_df = pd.DataFrame()
temp = pd.read_csv('/Users/bob/desktop/Research_data/tobii/42r-export.csv', sep = ',', encoding = 'latin-1')
raw_data_df['1'] = temp['Gaze point X']
raw_data_df['2'] = temp['Gaze point Y']
但是以下方法不起作用:
for i in files:
temp = pd.read_csv(path + i , sep = ',', encoding = 'latin-1')
print(temp['Gaze point X'])
raw_data_df[i+"x"] = temp['Gaze point X']
raw_data_df[i+"y"] = temp['Gaze point Y']
文件在哪里
path = "/Users/bob/desktop/Research_data/tobii/"
files = [f for f in listdir(path) if isfile(join(path,f))]
我没有返回列名为 i+"x" 或 i+"y" 的 pandas 数据框,而是得到一个列表列表。
这里是 raw_data_df 输出的示例
132660 857
132661 846
Name: Gaze point X, Length: 132662, dtype: int64
0 1206
1 1204
2 1205
3 1205
如何将多个 csv 文件的选定列连接到一个数据框中?
【问题讨论】:
-
什么是列表列表?
-
我返回数据框,它位于所有列的某种列表中