1 查询
testdf=df.query("date<='2020-02-03'").reset_index().drop(columns=['index'])
2 apply
2.1 将df中数值数据转化为-9999999,文本数据保持不变
def func(x):
try:
float(x)
except:
return True
else:
return False
df=df.apply(lambda x: x if func(x) else -9999999.0)
2.2 涉及两列的apply
df['score']=df.apply(lambda x: 1 if x['flag']==1 else x['score'],axis=1)
3 查看dataframe行/列的内容
3.1 查看dataframe中的一列
df['label']
3.2 查看dataframe中的多列
df[['label','id','name']]
3.3 df找到指定行
df.loc[1]
4 创建dataframe
4.1 由字典生成dataframe
df=pd.DataFrame.from_dict(word_ind_dict,orient='index',columns=['id'])
df = df.reset_index().rename(columns = {'index':'word','id':'index'})