Pandas速查

pandas中根据列的值选取多行数据

# 选取等于某些值的行记录,用==
data.loc[data['c']=='one'

对DataFrame中满足条件的行,列赋值

  a         b
0  1  0.068470
1  1  0.090775
2  1  0.923085
3  1  0.376297
4  1  0.701728
5  2  0.621320
6  2  0.866785
7  2  0.663804
8  2  0.978821
9  2  0.120308
# df.loc[row_index,col_index] = value
df.loc[df['a']==2,'b'] = 10

pandas按照条件查找

result.loc[row_indexer,'new_text'] = text_txt
df.loc[df['a']==2,'b'] = 10

pandas to_csv 最左边 多一列 的问题

df_train = pd.read_csv('data/train.csv',encoding='utf-8')
df_train.to_csv("train_preprocessed.csv",encoding='utf-8',index=False)

删除dataframe的一列

train = train.drop(['A'], axis=1)

其中axis=1代表的是要删除一列,而不是一行。

Series转换为List

Series.tolist()
posted @ 2021-12-17 11:28  zzflybird  阅读(55)  评论(0)    收藏  举报