★DataFrame零碎知识

修改1列的类型属性

    df['总金额'] = pd.to_numeric(df['总金额']) #转变dataframe的1列为数值型

修改某列数值
    df['流通市值'] = round(df['流通市值']/100000000,2)

dataframe数据筛选后求和: 
    df1=df[(df['age']>10) & (df['age']<30)]['profit'].sum() 
改变列顺序
    order = ['股票代码','股票简称',....']
    df = df[order] 

删除指定多列
    x=[4,7,10,11,12,13,15]  #列的序号,从0开始
    df.drop(df.columns[x], axis=1, inplace=True)

总行情、总列数:

    '行数'=sheet1.nrows,'列数'=sheet1.ncols

猜你喜欢

转载自www.cnblogs.com/sxinfo/p/10391069.html