pandas
来源:互联网 发布:网络摄像头原理 编辑:程序博客网 时间:2024/06/05 00:22
>>> import pandas as pd>>> df = pd.DataFrame([[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4]])>>> columns = ["col1","col2","col3","col4"]>>> df 0 1 2 30 1 1 1 11 2 2 2 22 3 3 3 33 4 4 4 4>>> df = pd.DataFrame([[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4]],columns=["col1","col2","col3","col4"])>>> df col1 col2 col3 col40 1 1 1 11 2 2 2 22 3 3 3 33 4 4 4 4>>> df.mean(axis=1)0 1.01 2.02 3.03 4.0dtype: float64>>> df.drop("col3",axis=1) col1 col2 col40 1 1 11 2 2 22 3 3 33 4 4 4>>> df.drop("1",axis=0)Traceback (most recent call last): File "<pyshell#13>", line 1, in <module> df.drop("1",axis=0) File "D:\Python\lib\site-packages\pandas\core\generic.py", line 2161, in drop new_axis = axis.drop(labels, errors=errors) File "D:\Python\lib\site-packages\pandas\core\indexes\base.py", line 3624, in drop labels[mask])ValueError: labels ['1'] not contained in axis>>> df.drop(1,axis=0) col1 col2 col3 col40 1 1 1 12 3 3 3 33 4 4 4 4>>> df.index()Traceback (most recent call last): File "<pyshell#15>", line 1, in <module> df.index()TypeError: 'RangeIndex' object is not callable>>> df.index = range(4)>>> df.indexRangeIndex(start=0, stop=4, step=1)>>> df col1 col2 col3 col40 1 1 1 11 2 2 2 22 3 3 3 33 4 4 4 4>>> df1 = df[['col3','col4']]>>> df1 col3 col40 1 11 2 22 3 33 4 4>>> df1.to_dict(orient='dict'){'col3': {0: 1, 1: 2, 2: 3, 3: 4}, 'col4': {0: 1, 1: 2, 2: 3, 3: 4}}>>> df1.to_dict(orient='records')[{'col3': 1, 'col4': 1}, {'col3': 2, 'col4': 2}, {'col3': 3, 'col4': 3}, {'col3': 4, 'col4': 4}]>>> df1.to_dict(orient='records')[0]{'col3': 1, 'col4': 1}>>>
阅读全文
0 0
- pandas
- pandas
- Pandas
- pandas
- pandas
- pandas
- pandas
- Pandas
- pandas
- pandas
- pandas
- pandas
- pandas
- pandas
- Pandas
- pandas小记:pandas数据结构
- pandas 基础
- Pandas使用
- 网络基础总结
- 数据库定期压缩
- 利用tensorflow1.2.1中的tensorboard显示数据流程图
- 如何从头搭建一个搜索引擎_numpy以及openCV
- 轻松学习python part2-控制语句
- pandas
- iOS封装浅谈-一句代码弹出actionSheet,如何优雅的设计一个ActionSheetManager
- java 二维码图片合成
- 6、自定义属性
- Livy:基于Apache Spark的REST服务
- qt中qlineedit和qtextedit右键菜单翻译成中文
- string?变量进行强解包发生崩溃的解决办法
- Fiddler死活抓不了HTTPS包解决办法
- yum 安装php-redis 扩展