df_data = pd.read_csv(path + '\\' + deletefile, sep=',') #以分隔符逗号读取数据
- df_data.loc['a'] # 找到行索引为‘a’的数据
- df_data.loc['a':'d'] #找到行索引为‘a’至’d‘的数据(包含’d‘行)
- df_data.iloc[0:3]#找到第一行至第三行的数据(不包含第四行)
- # df.ix[rows,columns]
- # replaces the deprecated ix function
- #df.ix[0:3,'Rev']
- df.loc[df.index[0:3],'Rev']
- # replaces the deprecated ix function
- #df.ix[5:,'col']
- df.loc[df.index[5:],'col']
- # replaces the deprecated ix function
- #df.ix[:3,['col', 'test']]
- df.loc[df.index[:3],['col', 'test']]
- df.drop_duplicates() #删除df中重复的数据
#将特定格式的字符串保存为csv文件
- string_data = "1111,2222,3333,,4444"
- pd_data = pd.Series(string_data)
- pd_data_expend = pd_data.str.split(",", expand=True)
- pd_data.shape
- pd_data_expend.shape
- row_name = df_data.index #行索引
- df_data.index.levels[1] #行索引有多个,索引第二个
- df_data.index.get_level_values(0)# 行索引有多个,索引第1个的值
- df_data.index.get_level_values(1).year# 行索引有多个,索引第2个的year值(针对日期)
- df_data.index.get_level_values(1).month# 行索引有多个,索引第2个的month值(针对日期)
- df_data.index.get_level_values(1).day# 行索引有多个,索引第2个的day值(针对日期)
参考链接:http://pandas.pydata.org/pandas-docs/stable/tutorials.html
由于笔者也是初学者,希望记录分享,以便方便学习,如有错误,欢迎批评指正,谢谢!