pandas常用命令
获取指定元素的列索引:
获取指定元素
at:通过行,列索引名称寻找
iat:通过行列序列值寻找
at比loc更快
df.at[``'Bob'``, ``'age'``] ``=` `60
print``(df.at[``'Bob'``, ``'age'``])
DF和Numpy互相转化
nmp=df.to_numpy()
nmp=df.values
DF插入新列
df.insert(loc=0, column=‘player’, value=player_vals)
DF删除列
df.drop('columns',axis=1,inplace=True)
索引修改
根据索引对原始数据重新排列
a=df_downsampled.reindex(index=range(len(df_downsampled)))
根据现有数据,重新建立索引
df_downsampled = df_downsampled.reset_index() # Reset the index
df_downsampled = df_downsampled.drop(columns=['index']) # Drop original index col
df数据拷贝
df = df_downsampled.copy()
查看Nan值
df_nan=df[df.isnull().T.any()]
根据行值获取指定行
df_skip = df[['date', 'hour','request_cnt']][df['date']==id_max]
查看空值所在的行
df_var_nan=df_var[df_var.isnull().T.any()]
data = data.drop(index = data[(data.ZH_Term_len == 0)].index.tolist())