[Tutor] Lock down windows with python+usb

2004-12-09 Thread Asif Iqbal
Hi All

Has anyone done any script like this? Use a python script for Windows XP
that will continuosly check if my USB is plugged in. So if I unplug my
USB flashdrive it will fork a screensaver with password lock.

Thanks for any idea/suggestion

-- 
Asif Iqbal
PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
"...it said: Install Windows XP or better...so I installed Solaris..."
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] test

2005-06-17 Thread Asif Iqbal
Hi All

I have a very simple problem and I am looking for the simplest solution.

I have a list of elements in a file. I like to find the total occurance
of each element in the list like this

10 string1
7 string2
1 string3

from a list which has only string1,string2 and string3 like this

string1
..
string2
...
string1
..
string3
...
...


I have a list of 3 lines and I think I have only 615 unique
elements. So I like the script not to take too much memory of the
system. I will be running it on Solaris 8

Thanks a lot

-- 
Asif Iqbal
PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
"..there are two kinds of people: those who work and those who take the 
credit...try
 to be in the first group;...less competition there."  - Indira Gandhi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] test

2005-06-17 Thread Asif Iqbal
On Fri, Jun 17, 2005 at 07:41:17AM, Chad Crabtree wrote:
> How about this.
>  >>> from random import choice
>  >>> alist=[choice(range(100)) for x in range(1000)] #just making a

How do I do this in python?
 alist < /tmp/logfile

The logfile has the list of entries.

-- 
Asif Iqbal
PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
"..there are two kinds of people: those who work and those who take the 
credit...try
 to be in the first group;...less competition there."  - Indira Gandhi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Authen::ACE

2006-03-24 Thread Asif Iqbal
Hi All

Does anyone know if there is any python module similar to Authen::ACE
available that I can use to authenticate against a RSA SecurID server?

Also, what would be a good irc chnl where python folks hang around?

Thanks

-- 
Asif Iqbal
PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
"..there are two kinds of people: those who work and those who take the 
credit...try
 to be in the first group;...less competition there."  - Indira Gandhi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] MIME parser

2008-12-11 Thread Asif Iqbal
I am looking for a way to feed a message from stdin to a python based
mime parser, detach all attachments and drop them to a dir, and then
send the email to the recipient.  The attachment(s) will be replaced
by an URL to a link.

So basically decouple the attachments (>1MB in size) and modify the
body by inserting an URL in the footer.

Has anyone done anything like this?


-- 
Asif Iqbal
PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] MIME parser

2008-12-11 Thread Asif Iqbal
On Thu, Dec 11, 2008 at 11:49:16AM, Asif Iqbal wrote:
> I am looking for a way to feed a message from stdin to a python based
> mime parser, detach all attachments and drop them to a dir, and then
> send the email to the recipient.  The attachment(s) will be replaced
> by an URL to a link.
> 
> So basically decouple the attachments (>1MB in size) and modify the
> body by inserting an URL in the footer.
> 
> Has anyone done anything like this?
> 

I am looking at email pkg. Now I need to find a way to feed the msg
from stdin and then detach all attachments and update the body with 
urls pointing to attachments

> 

-- 
Asif Iqbal
Google Chat: vad...@gmail.com
PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] XML parsing

2018-03-29 Thread Asif Iqbal
I am trying to extract all the *template-name*s, but no success yet

Here is a sample xml file

http://tail-f.com/ns/rest";>
  http://networks.com/nms";>
ALLFLEX-BLOOMINGTON
post-staging
full-mesh
ALLFLEX
http://networks.com/nms";>
  advanced-plus
  1000
  true
  true




with open('/tmp/template-metadata') as f:
import xml.etree.ElementTree as ET
root = ET.fromstring(f.read())

print len(root)
print root[0][0].text
for l in root.findall('template-metadata'):
print l


392
ALLFLEX-BLOOMINGTON


It prints the length of the tree and the first element of the first child,
but when I try to loop through to find all the 'template-name's
it does not print anything.

What am I doing wrong?


-- 
Asif Iqbal
PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] XML parsing

2018-03-29 Thread Asif Iqbal
On Thu, Mar 29, 2018 at 3:56 AM, Peter Otten <__pete...@web.de> wrote:

> Asif Iqbal wrote:
>
> > I am trying to extract all the *template-name*s, but no success yet
> >
> > Here is a sample xml file
> >
> > http://tail-f.com/ns/rest";>
> >   http://networks.com/nms";>
> > ALLFLEX-BLOOMINGTON
> > post-staging
> > full-mesh
> > ALLFLEX
> > http://networks.com/nms";>
> >   advanced-plus
> >   1000
> >   true
> >   true
> > 
> > 
> > 
> >
> > with open('/tmp/template-metadata') as f:
> > import xml.etree.ElementTree as ET
> > root = ET.fromstring(f.read())
> >
> > print len(root)
> > print root[0][0].text
> > for l in root.findall('template-metadata'):
> > print l
> >
> >
> > 392
> > ALLFLEX-BLOOMINGTON
> >
> >
> > It prints the length of the tree and the first element of the first
> child,
> > but when I try to loop through to find all the 'template-name's
> > it does not print anything.
> >
> > What am I doing wrong?
>
> You have to include the namespace:
>
> for l in root.findall('{http://networks.com/nms}template-metadata'):
>

How do I extract the 'template-name' ?

This is what I tried

 for l in root.findall('{http://networks.com/nms}template-metadata'):
print l.find('template-name').text

I am following the doc
https://docs.python.org/2/library/xml.etree.elementtree.html section
19.7.1.3 findall example

I get this error attribute error 'NoneType' object has no attribute text. I
do not understand why l.find('template-name') is NoneType.

Here is complete code with output.


import xml.etree.ElementTree as ET

xmlfile='''
http://tail-f.com/ns/rest";>
  http://networks.com/nms";>
ALLFLEX-BLOOMINGTON
post-staging
full-mesh
ALLFLEX
http://networks.com/nms";>
  advanced-plus
  1000
  true
  true
'''

root = ET.fromstring(xmlfile)
print root.tag
print root[0][0].text
for l in root.findall('{http://networks.com/nms}template-metadata'):
print l.find('template-name').text

collection
ALLFLEX-BLOOMINGTON

---AttributeError
   Traceback (most recent call
last) in () 19 print
root[0][0].text 20 for l in
root.findall('{http://networks.com/nms}template-metadata'):---> 21
print l.find('template-name').text
AttributeError: 'NoneType' object has no attribute 'text'





...
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Asif Iqbal
PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] XML parsing

2018-03-30 Thread Asif Iqbal
On Thu, Mar 29, 2018 at 3:41 PM, Peter Otten <__pete...@web.de> wrote:

> Asif Iqbal wrote:
>
> > On Thu, Mar 29, 2018 at 3:56 AM, Peter Otten <__pete...@web.de> wrote:
> >
> >> Asif Iqbal wrote:
> >>
> >> > I am trying to extract all the *template-name*s, but no success yet
> >> >
> >> > Here is a sample xml file
> >> >
> >> > http://tail-f.com/ns/rest";>
> >> >   http://networks.com/nms";>
> >> > ALLFLEX-BLOOMINGTON
> >> > post-staging
> >> > full-mesh
> >> > ALLFLEX
> >> > http://networks.com/nms";>
> >> >   advanced-plus
> >> >   1000
> >> >   true
> >> >   true
> >> > 
> >> > 
> >> > 
> >> >
> >> > with open('/tmp/template-metadata') as f:
> >> > import xml.etree.ElementTree as ET
> >> > root = ET.fromstring(f.read())
> >> >
> >> > print len(root)
> >> > print root[0][0].text
> >> > for l in root.findall('template-metadata'):
> >> > print l
> >> >
> >> >
> >> > 392
> >> > ALLFLEX-BLOOMINGTON
> >> >
> >> >
> >> > It prints the length of the tree and the first element of the first
> >> child,
> >> > but when I try to loop through to find all the 'template-name's
> >> > it does not print anything.
> >> >
> >> > What am I doing wrong?
> >>
> >> You have to include the namespace:
> >>
> >> for l in root.findall('{http://networks.com/nms}template-metadata'):
> >>
> >
> > How do I extract the 'template-name' ?
>
> I hoped you'd get the idea.
>
> > This is what I tried
> >
> >  for l in root.findall('{http://networks.com/nms}template-metadata'):
>
> Rinse and repeat:
>
> > print l.find('template-name').text
>
> should be
>
> print l.find('{http://networks.com/nms}template-name').text
>
> >
> > I am following the doc
> > https://docs.python.org/2/library/xml.etree.elementtree.html section
> > 19.7.1.3 findall example
> >
> > I get this error attribute error 'NoneType' object has no attribute text.
> > I do not understand why l.find('template-name') is NoneType.
>
> Take the time to read
>
> https://docs.python.org/2/library/xml.etree.elementtree.
> html#parsing-xml-with-namespaces


Thanks for the links and hints.

I got it working now

I used ns = { 'nms' : 'http://networks.com/nms
<http://networks.com/nms%7Dtemplate-name').text>' }

And then l.find('nms:template-name', ns)

I also want to extract the namespace and I see this gets me the namespace

  str(root[0]).split('{')[1].split('}')[0]

Is there a better way to extract the name space?




>
>
> > Here is complete code with output.
> >
> >
> > import xml.etree.ElementTree as ET
> >
> > xmlfile='''
> > http://tail-f.com/ns/rest";>
> >   http://networks.com/nms";>
> > ALLFLEX-BLOOMINGTON
> > post-staging
> > full-mesh
> > ALLFLEX
> > http://networks.com/nms";>
> >   advanced-plus
> >   1000
> >   true
> >   true
> > '''
> >
> > root = ET.fromstring(xmlfile)
> > print root.tag
> > print root[0][0].text
> > for l in root.findall('{http://networks.com/nms}template-metadata'):
> > print l.find('template-name').text
> >
> > collection
> > ALLFLEX-BLOOMINGTON
> >
> >
> 
> ---
> AttributeError
> >Traceback (most recent call
> > last) in () 19 print
> > root[0][0].text 20 for l in
> > root.findall('{http://networks.com/nms}template-metadata'):---> 21
> > print l.find('template-name').text
> > AttributeError: 'NoneType' object has no attribute 'text'
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Asif Iqbal
PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] XML parsing

2018-03-30 Thread Asif Iqbal
On Thu, Mar 29, 2018 at 9:40 PM, Asif Iqbal  wrote:

>
>
> On Thu, Mar 29, 2018 at 3:41 PM, Peter Otten <__pete...@web.de> wrote:
>
>> Asif Iqbal wrote:
>>
>> > On Thu, Mar 29, 2018 at 3:56 AM, Peter Otten <__pete...@web.de> wrote:
>> >
>> >> Asif Iqbal wrote:
>> >>
>> >> > I am trying to extract all the *template-name*s, but no success yet
>> >> >
>> >> > Here is a sample xml file
>> >> >
>> >> > http://tail-f.com/ns/rest";>
>> >> >   http://networks.com/nms";>
>> >> > ALLFLEX-BLOOMINGTON
>> >> > post-staging
>> >> > full-mesh
>> >> > ALLFLEX
>> >> > http://networks.com/nms";>
>> >> >   advanced-plus
>> >> >   1000
>> >> >   true
>> >> >   true
>> >> > 
>> >> > 
>> >> > 
>> >> >
>> >> > with open('/tmp/template-metadata') as f:
>> >> > import xml.etree.ElementTree as ET
>> >> > root = ET.fromstring(f.read())
>> >> >
>> >> > print len(root)
>> >> > print root[0][0].text
>> >> > for l in root.findall('template-metadata'):
>> >> > print l
>> >> >
>> >> >
>> >> > 392
>> >> > ALLFLEX-BLOOMINGTON
>> >> >
>> >> >
>> >> > It prints the length of the tree and the first element of the first
>> >> child,
>> >> > but when I try to loop through to find all the 'template-name's
>> >> > it does not print anything.
>> >> >
>> >> > What am I doing wrong?
>> >>
>> >> You have to include the namespace:
>> >>
>> >> for l in root.findall('{http://networks.com/nms}template-metadata'):
>> >>
>> >
>> > How do I extract the 'template-name' ?
>>
>> I hoped you'd get the idea.
>>
>> > This is what I tried
>> >
>> >  for l in root.findall('{http://networks.com/nms}template-metadata'):
>>
>> Rinse and repeat:
>>
>> > print l.find('template-name').text
>>
>> should be
>>
>> print l.find('{http://networks.com/nms}template-name').text
>>
>> >
>> > I am following the doc
>> > https://docs.python.org/2/library/xml.etree.elementtree.html section
>> > 19.7.1.3 findall example
>> >
>> > I get this error attribute error 'NoneType' object has no attribute
>> text.
>> > I do not understand why l.find('template-name') is NoneType.
>>
>> Take the time to read
>>
>> https://docs.python.org/2/library/xml.etree.elementtree.html
>> #parsing-xml-with-namespaces
>
>
> Thanks for the links and hints.
>
> I got it working now
>
> I used ns = { 'nms' : 'http://networks.com/nms
> <http://networks.com/nms%7Dtemplate-name').text>' }
>
> And then l.find('nms:template-name', ns)
>
> I also want to extract the namespace and I see this gets me the namespace
>
>   str(root[0]).split('{')[1].split('}')[0]
>
> Is there a better way to extract the name space?
>
>
>
This worked

ns = { 'nms' : root[0].tag.split('}')[0].split('{')[1] }

for l in root.findall('nms:template-metadata', ns):
print l.find('nms:template-name', ns).text

Although I think manually creating the ns dictionary looks cleaner :-)





>
>>
>>
>> > Here is complete code with output.
>> >
>> >
>> > import xml.etree.ElementTree as ET
>> >
>> > xmlfile='''
>> > http://tail-f.com/ns/rest";>
>> >   http://networks.com/nms";>
>> > ALLFLEX-BLOOMINGTON
>> > post-staging
>> > full-mesh
>> > ALLFLEX
>> > http://networks.com/nms";>
>> >   advanced-plus
>> >   1000
>> >   true
>> >   true
>> > '''
>> >
>> > root = ET.fromstring(xmlfile)
>> > print root.tag
>> > print root[0][0].text
>> > for l in root.findall('{http://networks.com/nms}template-metadata'):
>> > print l.find('template-name').text
>> >
>> > collection
>> > ALLFLEX-BLOOMINGTON
>> >
>> >
>> 
>> ---
>> AttributeError
>> >Traceback (most recent call
>> > last) in () 19 print
>> > root[0][0].text 20 for l in
>> > root.findall('{http://networks.com/nms}template-metadata'):---> 21
>> > print l.find('template-name').text
>> > AttributeError: 'NoneType' object has no attribute 'text'
>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
>
>
>
> --
> Asif Iqbal
> PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
> A: Because it messes up the order in which people normally read text.
> Q: Why is top-posting such a bad thing?
>
>


-- 
Asif Iqbal
PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Adding a new row to the dataframe with datetime as index

2018-05-21 Thread Asif Iqbal
Hi,

I am trying to add a new row to a new date in the dataframe like below

   df.loc['2018-01-24'] = [0,1,2,3,4,5]

And I am getting the following error

  ValueError: cannot set using a list-like indexer with a different length
than the value

I do have the right number of columns and I can lookup a row by the date

  df.loc['2018-01-23']

  df.shape
  (8034, 6)

  df.index
  DatetimeIndex(['2018-01-23', '2018-01-22', '2018-01-19', '2018-01-18',
   '2018-01-17', '2018-01-16', '2018-01-12', '2018-01-11',
   '2018-01-10', '2018-01-09',
   ...
   '1986-03-25', '1986-03-24', '1986-03-21', '1986-03-20',
   '1986-03-19', '1986-03-18', '1986-03-17', '1986-03-14',
   '1986-03-13', '2018-01-24'],
  dtype='datetime64[ns]', name='date', length=8034, freq=None)

Any idea how to add a new row to a new date?

--
Asif Iqbal
PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Adding a new row to the dataframe with datetime as index

2018-05-21 Thread Asif Iqbal
On Mon, May 21, 2018 at 9:28 AM, Peter Otten <__pete...@web.de> wrote:

> Asif Iqbal wrote:
>
> > Hi,
> >
> > I am trying to add a new row to a new date in the dataframe like below
> >
> >df.loc['2018-01-24'] = [0,1,2,3,4,5]
> >
> > And I am getting the following error
> >
> >   ValueError: cannot set using a list-like indexer with a different
> length
> > than the value
> >
> > I do have the right number of columns and I can lookup a row by the date
> >
> >   df.loc['2018-01-23']
> >
> >   df.shape
> >   (8034, 6)
> >
> >   df.index
> >   DatetimeIndex(['2018-01-23', '2018-01-22', '2018-01-19', '2018-01-18',
> >'2018-01-17', '2018-01-16', '2018-01-12', '2018-01-11',
> >'2018-01-10', '2018-01-09',
> >...
> >'1986-03-25', '1986-03-24', '1986-03-21', '1986-03-20',
> >'1986-03-19', '1986-03-18', '1986-03-17', '1986-03-14',
> >'1986-03-13', '2018-01-24'],
> >   dtype='datetime64[ns]', name='date', length=8034,
> freq=None)
> >
> > Any idea how to add a new row to a new date?
>
> My experiments indicate that there may be multiple values with the same
> key:
>
> > >>> import pandas as pd
> >>> df = pd.DataFrame([[1,2], [3,4], [5,6], [7,8]], index=["a", "b", "a",
> "a"])
> >>> df.loc["a"]
>0  1
> a  1  2
> a  5  6
> a  7  8
>
> [3 rows x 2 columns]
> >>> df.loc["a"] = [10, 20]
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python3/dist-packages/pandas/core/indexing.py", line 98,
> in
> __setitem__
> self._setitem_with_indexer(indexer, value)
>   File "/usr/lib/python3/dist-packages/pandas/core/indexing.py", line
> 422,
> in _setitem_with_indexer
> self.obj._data = self.obj._data.setitem(indexer, value)
>   File "/usr/lib/python3/dist-packages/pandas/core/internals.py", line
> 2396,
> in setitem
> return self.apply('setitem', *args, **kwargs)
>   File "/usr/lib/python3/dist-packages/pandas/core/internals.py", line
> 2376,
> in apply
> applied = getattr(blk, f)(*args, **kwargs)
>   File "/usr/lib/python3/dist-packages/pandas/core/internals.py", line
> 615,
> in setitem
> raise ValueError("cannot set using a list-like indexer "
> ValueError: cannot set using a list-like indexer with a different length
> than the value
>
> If found two ways to resolve this,
>
> (1) the obvious, ensure that the lengths are the same:
>
> >>> df.loc["a"] = [[10, 20], [30, 40], [50, 60]]
> >>> df
> 0   1
> a  10  20
> b   3   4
> a  30  40
> a  50  60
>
> (2) pass the key as a tuple:
>
> >>> df.loc["a",] = [1000, 2000]
> >>> df
>   0 1
> a  1000  2000
> b 3 4
> a  1000  2000
> a  1000  2000
>
> [4 rows x 2 columns]
>
> I suspect that you want neither, and instead avoid duplicate keys.



I want to overwrite the row

  print ( df.loc['2018-01-24'] )
  2018-01-24 0.0 1.0 2.0 3.0 4.0 NaN


  df.loc['2018-01-24'] = [0,1,2,3,4,5]
  ValueError: cannot set using a list-like indexer with a different length
than the value





>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Asif Iqbal
PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Adding a new row to the dataframe with datetime as index

2018-05-21 Thread Asif Iqbal
On Mon, May 21, 2018 at 4:59 PM, Peter Otten <__pete...@web.de> wrote:

> Asif Iqbal wrote:
>
> > On Mon, May 21, 2018 at 9:28 AM, Peter Otten <__pete...@web.de> wrote:
> >
> >> Asif Iqbal wrote:
> >>
> >> > Hi,
> >> >
> >> > I am trying to add a new row to a new date in the dataframe like below
> >> >
> >> >df.loc['2018-01-24'] = [0,1,2,3,4,5]
> >> >
> >> > And I am getting the following error
> >> >
> >> >   ValueError: cannot set using a list-like indexer with a different
> >> length
> >> > than the value
> >> >
> >> > I do have the right number of columns and I can lookup a row by the
> >> > date
> >> >
> >> >   df.loc['2018-01-23']
> >> >
> >> >   df.shape
> >> >   (8034, 6)
> >> >
> >> >   df.index
> >> >   DatetimeIndex(['2018-01-23', '2018-01-22', '2018-01-19',
> >> >   '2018-01-18',
> >> >'2018-01-17', '2018-01-16', '2018-01-12', '2018-01-11',
> >> >'2018-01-10', '2018-01-09',
> >> >...
> >> >'1986-03-25', '1986-03-24', '1986-03-21', '1986-03-20',
> >> >'1986-03-19', '1986-03-18', '1986-03-17', '1986-03-14',
> >> >'1986-03-13', '2018-01-24'],
> >> >   dtype='datetime64[ns]', name='date', length=8034,
> >> freq=None)
> >> >
> >> > Any idea how to add a new row to a new date?
> >>
> >> My experiments indicate that there may be multiple values with the same
> >> key:
> >>
> >> > >>> import pandas as pd
> >> >>> df = pd.DataFrame([[1,2], [3,4], [5,6], [7,8]], index=["a", "b",
> "a",
> >> "a"])
> >> >>> df.loc["a"]
> >>0  1
> >> a  1  2
> >> a  5  6
> >> a  7  8
> >>
> >> [3 rows x 2 columns]
> >> >>> df.loc["a"] = [10, 20]
> >> Traceback (most recent call last):
> >>   File "", line 1, in 
> >>   File "/usr/lib/python3/dist-packages/pandas/core/indexing.py", line
> 98,
> >> in
> >> __setitem__
> >> self._setitem_with_indexer(indexer, value)
> >>   File "/usr/lib/python3/dist-packages/pandas/core/indexing.py", line
> >> 422,
> >> in _setitem_with_indexer
> >> self.obj._data = self.obj._data.setitem(indexer, value)
> >>   File "/usr/lib/python3/dist-packages/pandas/core/internals.py", line
> >> 2396,
> >> in setitem
> >> return self.apply('setitem', *args, **kwargs)
> >>   File "/usr/lib/python3/dist-packages/pandas/core/internals.py", line
> >> 2376,
> >> in apply
> >> applied = getattr(blk, f)(*args, **kwargs)
> >>   File "/usr/lib/python3/dist-packages/pandas/core/internals.py", line
> >> 615,
> >> in setitem
> >> raise ValueError("cannot set using a list-like indexer "
> >> ValueError: cannot set using a list-like indexer with a different length
> >> than the value
> >>
> >> If found two ways to resolve this,
> >>
> >> (1) the obvious, ensure that the lengths are the same:
> >>
> >> >>> df.loc["a"] = [[10, 20], [30, 40], [50, 60]]
> >> >>> df
> >> 0   1
> >> a  10  20
> >> b   3   4
> >> a  30  40
> >> a  50  60
> >>
> >> (2) pass the key as a tuple:
> >>
> >> >>> df.loc["a",] = [1000, 2000]
> >> >>> df
> >>   0 1
> >> a  1000  2000
> >> b 3 4
> >> a  1000  2000
> >> a  1000  2000
> >>
> >> [4 rows x 2 columns]
> >>
> >> I suspect that you want neither, and instead avoid duplicate keys.
> >
> >
> >
> > I want to overwrite the row
> >
> >   print ( df.loc['2018-01-24'] )
> >   2018-01-24 0.0 1.0 2.0 3.0 4.0 NaN
> >
> >
> >   df.loc['2018-01-24'] = [0,1,2,3,4,5]
> >   ValueError: cannot set using a list-like indexer with a different
> length
> > than the value
>
> Can you post a self-contained example, i. e. a small script that also
> creates a -- hopefully small -- DataFrame and then triggers the ValueError?
>
>
It is working after I ran a df = df.sort_index()

I was looping through new dates and feeding predicted data to new row for
next day, but I was going in the wrong direction.


-- 
Asif Iqbal
PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor