pandas常用方法示例 2

from pandas import DataFrame
import numpy as np
import pandas as pd

t={
    "age": [18, 30, np.nan, 40, np.nan, 30],
    "city": ["BeiJing", "ShangHai", "GuangZhou", "ShenZhen", ‘BeiJing‘, "ShangHai"],
    "sex": [None, "male", "female", "male", np.nan, "unknown"],
    "birth": ["2000-02-10", "1988-10-17", None, "1978-08-08", np.nan, "1988-10-17"],
    "score":[11,7,33,44,22,33],
    "naem":[‘sdf‘,‘aa‘,‘bb‘,‘tt‘,‘ere‘,‘tt‘],
    "name":[‘sdf 11‘,‘aa 22‘,‘bb 33‘,‘tt 44‘,‘ere 55‘,‘tt 66‘]
}

df =DataFrame(t,index=[‘num1‘,‘num2‘,‘num3‘,‘num4‘,‘num5‘,‘num6‘])
print(df.loc[df.index[[2,3]],[‘age‘,‘name‘]])

相关推荐