#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018/5/24 15:03
# @Author : zhang chao
# @File : s.py
from scipy import linalg as lg
#按标签选择
#通过标签选择多轴 import pandas as pd
import numpy as np dates = pd.date_range('', periods=8)
df = pd.DataFrame(np.random.randn(8,4), index=dates, columns=list('ABCD'))
print("df:")
print(df)
print('-'*50)
s=pd.Series(list(range(10,18)),index=pd.date_range('', periods=8))
df["F"]=s#新加一列元素F
print("df['F']=s")
print(df)
print('-'*50)
df.at[dates[0],"A"]=99
print("df.at[dates[0],'A']=99")
print(df)
print('-'*50)
print("df.iat[1,1]=-66")
df.iat[1,1]=-66
print(df)
print('-'*50)
print("df.loc[:,'D']=np.array([4]*len(df))")
df.loc[:,"D"]=np.array([4]*len(df))
print(df)
print('-'*50)
df2=df.copy()#拷贝
print('-'*50)
print("")
df2[df2>0]=-df2#将df2中的所有大于0的元素值 都改为小于0的
print (df2)
D:\Download\python3\python3.exe D:/Download/pycharmworkspace/s.py
df:
A B C D
2017-01-01 -0.598774 1.076390 -0.642006 -0.089715
2017-01-02 -0.438976 1.063627 0.387825 1.312049
2017-01-03 0.101879 0.469225 0.860522 0.086417
2017-01-04 -0.670031 1.974935 -0.570337 0.478371
2017-01-05 0.250046 -1.385470 -0.893637 -1.786031
2017-01-06 0.876446 -0.167285 -0.475356 -0.145381
2017-01-07 0.291258 0.676994 -1.953909 -0.609507
2017-01-08 -0.569716 0.749637 1.038614 -0.502682
--------------------------------------------------
df['F']=s
A B C D F
2017-01-01 -0.598774 1.076390 -0.642006 -0.089715
2017-01-02 -0.438976 1.063627 0.387825 1.312049
2017-01-03 0.101879 0.469225 0.860522 0.086417
2017-01-04 -0.670031 1.974935 -0.570337 0.478371
2017-01-05 0.250046 -1.385470 -0.893637 -1.786031
2017-01-06 0.876446 -0.167285 -0.475356 -0.145381
2017-01-07 0.291258 0.676994 -1.953909 -0.609507
2017-01-08 -0.569716 0.749637 1.038614 -0.502682
--------------------------------------------------
df.at[dates[0],'A']=99
A B C D F
2017-01-01 99.000000 1.076390 -0.642006 -0.089715 10
2017-01-02 -0.438976 1.063627 0.387825 1.312049 11
2017-01-03 0.101879 0.469225 0.860522 0.086417 12
2017-01-04 -0.670031 1.974935 -0.570337 0.478371 13
2017-01-05 0.250046 -1.385470 -0.893637 -1.786031 14
2017-01-06 0.876446 -0.167285 -0.475356 -0.145381 15
2017-01-07 0.291258 0.676994 -1.953909 -0.609507 16
2017-01-08 -0.569716 0.749637 1.038614 -0.502682 17
--------------------------------------------------
df.iat[1,1]=-66
A B C D F
2017-01-01 99.000000 1.076390 -0.642006 -0.089715 10
2017-01-02 -0.438976 -66.000000 0.387825 1.312049 11
2017-01-03 0.101879 0.469225 0.860522 0.086417 12
2017-01-04 -0.670031 1.974935 -0.570337 0.478371 13
2017-01-05 0.250046 -1.385470 -0.893637 -1.786031 14
2017-01-06 0.876446 -0.167285 -0.475356 -0.145381 15
2017-01-07 0.291258 0.676994 -1.953909 -0.609507 16
2017-01-08 -0.569716 0.749637 1.038614 -0.502682 17
--------------------------------------------------
df.loc[:,'D']=np.array([4]*len(df))
A B C D F
2017-01-01 99.000000 1.076390 -0.642006 10
2017-01-02 -0.438976 -66.000000 0.387825 11
2017-01-03 0.101879 0.469225 0.860522 12
2017-01-04 -0.670031 1.974935 -0.570337 13
2017-01-05 0.250046 -1.385470 -0.893637 14
2017-01-06 0.876446 -0.167285 -0.475356 15
2017-01-07 0.291258 0.676994 -1.953909 16
2017-01-08 -0.569716 0.749637 1.038614 17
--------------------------------------------------
-------------------------------------------------- A B C D F
2017-01-01 -99.000000 -1.076390 -0.642006 -4 -10
2017-01-02 -0.438976 -66.000000 -0.387825 -4 -11
2017-01-03 -0.101879 -0.469225 -0.860522 -4 -12
2017-01-04 -0.670031 -1.974935 -0.570337 -4 -13
2017-01-05 -0.250046 -1.385470 -0.893637 -4 -14
2017-01-06 -0.876446 -0.167285 -0.475356 -4 -15
2017-01-07 -0.291258 -0.676994 -1.953909 -4 -16
2017-01-08 -0.569716 -0.749637 -1.038614 -4 -17 Process finished with exit code 0

pandas设置值、更改值的更多相关文章

  1. pandas设置值-【老鱼学pandas】

    本节主要讲述如何根据上篇博客中选择出相应的数据之后,对其中的数据进行修改. 对某个值进行修改 例如,我们想对数据集中第2行第2列的数据进行修改: import pandas as pd import ...

  2. Pandas设置值

    1.创建数据 >>> dates = pd.date_range(', periods=6) >>> df = pd.DataFrame(np.arange(24) ...

  3. UC浏览器中,设置了position: fixed 的元素会遮挡z-index值更高的同辈元素

    "UC浏览器中,设置了position: fixed 的元素会遮挡z-index值更高的同辈元素(非fixed)." 我们使用的artDialog弹窗中,在UC浏览器中,如果页面高 ...

  4. Panda的学习之路(3)——pandas 设置特定的值&处理没有数据的部分

    先设定好我们的dataframe: # pandas 设置特定的值 dates=pd.date_range(',periods=6) # print(dates) df=pd.DataFrame(np ...

  5. easyUI validatebox设置值和获取值,以及属性和方法

    一:表单元素使用easyui时,textbox和validatebox设置值和获取值的方式不一样[转] 1.为text-box设置值只能使用id选择器选择表单元素,只能使用textbox(" ...

  6. easyui-textbox 和 easyui-validatebox 设置值和获取值

    表单作如下定义:该input使用easyui的"easyui-textbox" <input id="addSnumber" style="wi ...

  7. JS表单设置值

    //表单设置值 $.fn.setForm = function(jsonValue) { var obj = this; $.each(jsonValue, function (name, ival) ...

  8. 从redis中取值如果不存在设置值,使用Redisson分布式锁【我】

    用到的jar包: <!-- Redis客户端 --> <dependency> <groupId>redis.clients</groupId> < ...

  9. [js]作用域链查找规则获取值和设置值

    作用域链查找规则获取值和设置值 <script> /** 1.作用域链查找规则 私有作用域出现的一个变量不是私有的,则往上一级作用域查找,上级作用域没有则继续向上级查找,一直找到windo ...

随机推荐

  1. 转载 jQuery和js自定义函数和文件的方法(全网最全)

    jQuery和js自定义函数和文件的方法(全网最全)    版权声明:本文为像雾像雨又像风_http://blog.csdn.net/topdandan的原创文章,未经允许不得转载. https:// ...

  2. call()、delegatecall()

    call()当使用方法是:require(msg.sender.call.value(_weiToWithdraw)());则作用是将_weiToWithdraw个以太币发送给msg.sender地址 ...

  3. ethereum/EIPs-607 Hardfork Meta: Spurious Dragon硬分叉相关

    eip title author type status created requires 607 Hardfork Meta: Spurious Dragon Alex Beregszaszi Me ...

  4. Oracle 11g rac 添加新节点测试

    [转]https://blog.csdn.net/shiyu1157758655/article/details/60877076 前期准备: 操作系统设置OS版本必须相同,检查内核参数,系统内存.C ...

  5. leetcode46. Permutations 、47. Permutations II、 剑指offer字符串的排列

    字符串排列和PermutationsII差不多 Permutations第一种解法: 这种方法从0开始遍历,通过visited来存储是否被访问到,level代表每次已经存储了多少个数字 class S ...

  6. POJ2387(dijkstra堆优化)

    Til the Cows Come Home Bessie is out in the field and wants to get back to the barn to get as much s ...

  7. eclpse安装jetty插件

    公司不用tomcat,使用的是jetty,那么学习一下如何在eclipse中安装jetty插件.

  8. [Oracle]为何Archivelog 没有马上被删除

    [Oracle]为何Archivelog 没有马上被删除 客户设置了 Archivelog 的 deletion policy 是 CONFIGURE ARCHIVELOG DELETION POLI ...

  9. [数据可视化之一]Pandas单变量画图

    Pandas单变量画图 Bar Chat Line Chart Area Chart Histogram df.plot.bar() df.plot.line() df.plot.area() df. ...

  10. ActiveMQ在C#中的应用

    本文是在.NET Framework框架下的应用,截止到目前ActiveMQ还不支持.NET Core,而RabbitMQ已经支持.NET Core,希望ActiveMQ能尽快支持. ActiveMQ ...