嵌入式音频接口ESAI实战:从寄存器配置到TDM总线设计
2026/6/13 16:56:55
UFO 报告数据(uforeports.csv)
ufo = pd.read_csv('uforeports.csv')ufo['Shape Reported'].value_counts(dropna=False)(包括缺失值)ufo['Shape Reported'].fillna(value='VARIOUS', inplace=True)将缺失值用VARIOUS替换loc选择指定行/列(例如ufo.loc[[0,1,2], :]、ufo.loc[:, ['Colors Reported','Shape Reported','State']])ufo[ufo.City == 'Oakland']或ufo.loc[ufo.City == 'Oakland','State'].drop())、查看尾部数据(.head()/.tail()等)pandas 索引(Index)及drinksbycountry.csv
drinks = pd.read_csv('drinksbycountry.csv')drinks.index、drinks.columns、drinks.shapedrinks.set_index('country', inplace=True),随后可用drinks.loc['Brazil','beer_servings']用国家名访问行。drinks.reset_index(inplace=True)drinks.index.name = 'country'或drinks.index.name = Nonedrinks.describe()和对统计结果的定位(例如drinks.describe().loc['25%','beer_servings'])选择多行多列与位置索引
loc用法:基于标签选择行列(可用行标签切片、列表或布尔掩码)。iloc用法:基于整数位置选择(例如ufo.iloc[:,0:4])。ufo.loc[:, 'Colors Reported':'Time'](使用列名范围切片)其它实用示例
pd.read_table('movieusers.csv', header=None, sep='|')drinks.continent.value_counts().sort_index()ufo['Shape Reported'].value_counts(dropna=False)ufo['Shape Reported'].fillna(value='VARIOUS',inplace=True)ufo['Shape Reported'].value_counts()说明:先查看包含 NaN 的统计,再用fillna填充,最后确认填充结果。
drinks=pd.read_csv('drinksbycountry.csv')drinks.set_index('country',inplace=True)drinks.loc['Brazil','beer_servings']说明:把country设置为索引后,可直接用国家名定位对应行的数据。
loc/iloc示例:# 基于标签选择:ufo.loc[[0,1,2],:]# 基于位置选择:ufo.iloc[:,0:4]# 选择列范围:ufo.loc[:,'Colors Reported':'Time']drinks.describe().loc['25%','beer_servings']