pythonpandas设置索引_python – pandas:使用(row,col)索引设置值
我不确定跟随你,但是你使用DataFrame.ix选择/设置单个元素:
In [79]: M
Out[79]:
one two three four
a -0.277981 1.500188 -0.876751 -0.389292
b -0.705835 0.108890 -1.502786 -0.302773
c 0.880042 -0.056620 -0.550164 -0.409458
d 0.704202 0.619031 0.274018 -1.755726
In [75]: M.ix[0]
Out[75]:
one -0.277981
two 1.500188
three -0.876751
four -0.389292
Name: a
In [78]: M.ix[0,0]
Out[78]: -0.27798082190723405
In [81]: M.ix[0,0] = 1.0
In [82]: M
Out[82]:
one two three four
a 1.000000 1.500188 -0.876751 -0.389292
b -0.705835 0.108890 -1.502786 -0.302773
c 0.880042 -0.056620 -0.550164 -0.409458
d 0.704202 0.619031 0.274018 -1.755726
In [84]: M.ix[(0,1),(0,1)] = 1
In [85]: M
Out[85]:
one two three four
a 1.000000 1.000000 -0.876751 -0.389292
b 1.000000 1.000000 -1.502786 -0.302773
c 0.880042 -0.056620 -0.550164 -0.409458
d 0.704202 0.619031 0.274018 -1.755726
您还可以按索引切片:
In [98]: M.ix["a":"c","one"] = 2.0
In [99]: M
Out[99]:
one two three four
a 2.000000 1.000000 -0.876751 -0.389292
b 2.000000 1.000000 -1.502786 -0.302773
c 2.000000 -0.056620 -0.550164 -0.409458
d 0.704202 0.619031 0.274018 -1.755726
pythonpandas设置索引_python – pandas:使用(row,col)索引设置值相关推荐
- python 重置索引_python pandas 对series和dataframe的重置索引reindex方法
reindex更多的不是修改pandas对象的索引,而只是修改索引的顺序,如果修改的索引不存在就会使用默认的None代替此行.且不会修改原数组,要修改需要使用赋值语句. series.reindex( ...
- python附加索引_python – 附加两个多索引的pandas数据帧
你能帮忙附上两个多索引的熊猫数据帧吗?试图将df_future附加到df_current. COMPANY和DATE是索引. df_current VALUE COMPANY DATE 7/27/20 ...
- python numpy矩阵索引_python – Numpy中的矩阵索引
索引后查看形状: In [295]: A=np.matrix([1,2,3]) In [296]: A.shape Out[296]: (1, 3) In [297]: A[0] Out[297]: ...
- python 返回列表索引_python怎么返回列表元素索引?
python中可以使用index()方法返回列表中指定元素的索引. Python index() 方法检测字符串中是否包含子字符串 str ,如果指定 beg(开始) 和 end(结束) 范围,则检查 ...
- python增加索引_python – 为numpy数组添加索引
我有一个numpy数组: prob_rf = [[0.4, 0.4, 0.4], [0.5, 0.5, 0.5], [0.6, 0.6, 0.6]] 我想为每个内部数组添加一个索引号: prob_rf ...
- pandas重新设置列索引_python数据分析包Pandas(一)
pandas是一个python包,提供快速,灵活和富有表现力的数据结构,旨在使"关系"或"标记"数据的使用既简单又直观. pandas的两个主要数据结构Seri ...
- python pandas dataframe 不显示索引_Python DataFrame 设置输出不显示index(索引)值的方法...
Python DataFrame 设置输出不显示index(索引)值的方法 在输出代码行中,加入"index=False"如下: m_pred_survived.to_csv(&q ...
- pandas使用query函数基于判断条件获得dataframe中满足条件的数据行(row)的索引列表(index of rows matching conditions in dataframe)
pandas使用query函数基于判断条件获得dataframe中满足条件的数据行(row)的索引列表(index of rows matching conditions in dataframe) ...
- pandas获取dataframe中索引值最大值所在的数据行(get dataframe row of max index value)
pandas获取dataframe中索引值最大值所在的数据行(get dataframe row of max index value) 目录 pandas获取dataframe中索引值最大值所在的数 ...
最新文章
- SnowFlake唯一ID生成器
- CAS(compareAndSwap)原理
- 手持机连不上信道设置为13的AP
- 【三种可能问题】RuntimeError: cuDNN error: CUDNN_STATUS_NOT_SUPPORTED
- Python 常见优化技巧,让你的程序溜溜的跑起来!
- java数据跑不出来,6000条数据,java下跑了20多分钟了还没跑完,求教怎么改进
- 【深度学习】——物体检测细节处理(NMS、样本不均衡、遮挡物体)
- 序列化框架MJExtension详解 + iOS ORM框架
- webpack 优化react项目没有解决的问题
- HNUCM 1284:二叉树遍历
- 如何在网页中添加 GitHub Corners
- JSP中文乱码解决方案了解和TOMCAT中文乱码解决
- 快讯:预装Ubuntu 11.10小电脑南非开卖
- flow java.lang.IllegalArgumentException: Unable to create call adapter for
- 0428-项目再开发2.0
- 在windows下启动容器时,报 the input device is not a TTY. If you are using mintty, try prefixing the command
- 浅谈AutoCAD下载安装的那些三两事!
- android 重启后进入安全模式_Android手机如何进入离开安全模式?
- python什么意思d_python里d是什么意思
- rebar3使用介绍(三)命令