我有一个类似df的列:
AttributeError Traceback (most recent call last)
<ipython-input-82-50bfcf5c498e> in <module>()
1
2 # Load dataset
----> 3 dataset = load_dataset("data/training.csv", ['target', 't_id', 'created_at', 'query', 'user', 'text'])
4 # Remove unwanted columns from dataset
5 n_dataset = remove_unwanted_cols(dataset, ['t_id', 'created_at', 'query', 'user'])
<ipython-input-73-f3f5beb3714c> in load_dataset(training, cols)
1 def load_dataset(training, cols):
----> 2 dataset = pd.read_csv(training.csv, encoding='latin-1')
3 dataset.columns = cols
4 return dataset
AttributeError: 'str' object has no attribute 'csv'
我正在尝试创建一个可以应用于新列的函数,它将插入> .75
的列表元素赞:
col1
[('asd', 0.99), ('vcxx', 0.77), ('dfs', 0.32)]
[('fds', 0.97), ('xcvxc', 0.71), ('vcbtxx', 0.54), ('bfed', 0.12)]
[('fdssa', 0.98), ('asdfd', 0.61)]
答案 0 :(得分:4)
尝试一下:
df['new_col'] = df.col1.apply(lambda x: [val for val in x if val[1] > 0.75])