I have a column in a pandas dataframe dfr in which there is a empty list. When I try to append it, the entire column is changed.   Below is the code attached.  N = 10 Nr = list(range(10)) dfr = pd.DataFrame(Nr,columns = ['ID']) dfr['Assignment'] = [[]] * dfr.shape[0] for i in range(N):     dfr.loc[i][1].append(i)     dfr   Now when I run this, the whole assignment column changes. Can anyone help me here. I just need to have 1 value of i in the list in each row.
410
I needed to create a list of lists in Python, so I typed the following: my_list = [[1] * 4] * 3  The list looked like this: [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]    Then I changed one of the innermost values: my_list[0][0] = 5  Now my list looks like this: [[5, 1, 1, 1], [5, 1, 1, 1], [5, 1, 1, 1]]    which is not what I wanted or expected. Can someone please explain what's going on, and how to get around it?
13837
I'm searching a way to append a group in Python.  It should behave exactly like the Append function (ShiftF1) works, all objects should be local and editable. The idea is to append a character (with rig etc.) via Python and not Link it (to be able to modify it without making everything local one by one).  Thanks
43578
I've got a spreadsheet in Google Drive and one column is meant for the date the entry is made. Is there a button to do this? I'm aware of the functions =NOW() and =TODAY() but their description says "the value is updated when the document recalculates". However I reopened the document a few minutes latter and it still had the same time. Why is this?  It would be even easier that when I start typing in a new row the column for the date auto-populates.
2612
Sometimes you are faced with problems that you can not understand. Now I have a hidden column inside my Issue tracking list, which is used to store a series of string to be read by the list workflow. Now I set a default value for the column such as "ABC", and I set it as a hidden field, so user will not be able to modify its value or see it. But the problem is that if admin users change the default value of the hidden field from the "List Option>> List Setting >> Columns >> click on the hidden column", then its type inside the content type will be changed from hidden to optional and the field will appear inside the New and edit forms, so can any one advice on this please? Is there a way to prevent the hidden column from being set as optional when its default value is changed ?   I have the following problem inside my team site:   I set a site column as hidden from the list content type. then I modify the column at the list level, where I changed its default value. then after that the column will be set as optional instead of hidden at the list content type.   So can anyone advice on this ? How can I remove this behavior ?
44305
I imported the coordinates from an Excel table. They show as single points as intended. Now I want to add columns to the attribute table, but I'm not able to edit it. I wanted to import the following columns from Excel as well, but that doesn't seem to work either.  Sorry for the noob-question, but I couldn't find anything relating the theme through google and such.  Ok, with pictures then: I want to use that to add columns with information to these       You see, the small pensil thingy is greyed out, so I can't edit anything in this layer and I can't add any information to my points.  If I try Ale suggestion I get this error:
96022
I had the following exception thrown at me when trying to process more than one selected records via a custom button in the list view.    Class Code  global class MerchandiseInventoryClass {      webservice static void ConverttoInventory(String[] merchandise_id)    {        //Convert Merchandise collection into Inventory Collection...         Merchandise__c[] merchandise_collection = [SELECT ID,Author__c,Book_Title__c,Edition__c,Publisher__c,Total_Merchandise_QtyTotal_Qty__c,Status__c FROM Merchandise__c WHERE ID = :merchandise_id];          Inventory__c i = new Inventory__c(); //Line 1        List&lt;Inventory__c&gt; newInventory = new List&lt;Inventory__c&gt;();        for(Merchandise__c m : merchandise_collection )        {            if(m.Status__c !='Fully Converted')            {            i.Author__c = m.Author__c ;            i.Book_Title__c = m.Book_Title__c;            i.Edition__c = m.Edition__c;            i.Publisher__c = m.Publisher__c;            i.Qty_Available__c = m.Total_Merchandise_QtyTotal_Qty__c;            i.Merchandise__c = m.Id;            m.Uninventoried_Qty__c = 0;            m.Status__c = 'Fully Converted';            newInventory.add(i);            }        }        insert newInventory;        update merchandise_collection;    }  }   By moving the Line 1 to within the for loop solved the issue for me.  Thanks to this post (refer the Best Answer in that post)    What puzzles me is that WHY i have to instantiate "i" for every iteration within the loop.  Why the list collection ("newInventory") is complaining that are duplicate elements and why should it even confuse in the first place when I am performing an "insert" even ?
76742
Shapefile: "table1.shp"   Field name: "Name" Field name: "Result"   Flat file: "referenceTable"   Field name: "STREET" Field name: "AKA"   I need to compare the value "Name" in "table1.shp" to the value "STREET" in "referenceTable"  If the values are the same then put the "AKA" value into the "Result" in "table1.shp"     Here is my code.  I got stuck on accessing the elements from the array  import arcpy, os, sys, string from array import *   table1 = "G:\\xStreetNew\\table1.shp" table1_column = ['Name', 'Result'] referenceTable = "G:\\xStreetNew\\Test.gdb\\referenceTable" referenceTable_column = ['STREET', 'AKA']  referenceTable_List = [] with arcpy.da.SearchCursor(referenceTable, referenceTable_column) as rCur: for r_row in rCur:     reference_row = r_row[0].split(",")     referenceTable_List.insert(0,reference_row) ##print sorted(referenceTable_List)  Table1_Update_Cursor = arcpy.da.UpdateCursor(table1, "Name") for row in Table1_Update_Cursor:   if row[0] == None:   row[0] = row[0] else:   row[0] = row[0].replace(";",",")   Table1_Update_Cursor.updateRow(row)  table1_List = [] with arcpy.da.SearchCursor(table1, table1_column) as tCur: for t_row in tCur:     row = t_row[0].split(",")     table1_List.insert(0,row) ##print sorted(table1_List)  Table1_row = len(table1_List) Table1_column = len([table1_List]) ref_row = len(referenceTable_List) for i in range(0,Table1_row):  #Table Row   for ii in range(0,Table1_column):   #Table Column     print table1_List[i][ii]   Below was my old post.  Sorry for the confusion.  I have a shapefile named "table1.shp".     I would like to get all values from fielname "Name" from this table and put them into a list. Able to output each element from the list     So far, I'm able to create a list but not too sure how to get to value "AVENUE 33" or "CHAPMAN ST"  This is my code:  import arcpy, os, sys, string from array import *   table1 = "G:\\xStreetNew\\table1.shp" referenceTable = "G:\\xStreetNew\\Test.gdb\\referenceTable" cursor = arcpy.da.UpdateCursor(table1, "Name") for row in cursor: if row[0] == None:     row[0] = row[0] else:     row[0] = row[0].replace(";",",") cursor.updateRow(row) table1_column = ['Name'] table1_curObj = arcpy.da.SearchCursor(table1, table1_column) table1_List = [] for row in table1_curObj:    table1_row = row[0].split(",")    table1_List.insert(0,table1_row)    print table1_List[0]
61628
I would like to convert several range of columns into rows, and keeping the association to the original col/row source  Sample source sheet  --------------------------------------------------- | Data 1 | 1/1/2018 | 1/2/2018 | 1/3/2018 | etc...365 days | --------------------------------------------------- | name 1  |    25    |   30     |    5     | etc...|  --------------------------------------------------- | name 2  |    2     |          |    4     | etc...| --------------------------------------------------- | etc ... 100 rows   Expected Results  --------------------------------------------------- | Data 1 |   Date      |  Value   |  --------------------------------------------------- | name 1  |  1/1/2018   |   25     |    --------------------------------------------------- | name 1  |  1/2/2018   |   30     |    --------------------------------------------------- | name 1  |  1/3/2018   |   5      |    --------------------------------------------------- | name 1  |  etc.. 365 days --------------------------------------------------- | name 2  |  1/1/2018   |   2      |    --------------------------------------------------- | name 2  |  1/2/2018   |          |    --------------------------------------------------- | name 2  |  1/3/2018   |   4      |    --------------------------------------------------- | name 2  |  etc.. 365 days --------------------------------------------------- | etc ... for each change of name pull all the col dates/values   Current results  --------------------------------------------------- | Data 1 |   Date      |  Value   |  --------------------------------------------------- | name 1  |  1/1/2018   |   25     |    --------------------------------------------------- |         |  1/2/2018   |   30     |    --------------------------------------------------- |         |  1/3/2018   |   5      |    --------------------------------------------------- |         |  etc.. 365 days                      I have to copy down to bring in "name 1" for each date  --------------------------------------------------- | name 2  |  1/1/2018   |   2      |             now update the formula to bring in the second item for the sequence of dates --------------------------------------------------- |         |  1/2/2018   |          |    --------------------------------------------------- |         |  1/3/2018   |   4      |    --------------------------------------------------- |         |  etc.. 365 days --------------------------------------------------- | etc ...     =Sheet1!A:A I can bring in the name from the source list, but I have to copy it down for the number of dates.  How can I have it match the number of dates?  and be dynamic to update as dates/values are added Edit: trying to use split and rept to count the number of times to repeat, then transpose.. =transpose(rept(split(arrayformula(concatenate(Sheet1!A:A&amp;"1")),"1",True, True),COUNTA(Sheet1!I1:ZZ1)))  =TRANSPOSE(Sheet1!$C$1:$Z$1) I can use transpose to get the dates/values, but it's fixed range.  How can I make it dynamic to import dates as they are added?
14938
Is there some clever way to do this in SQLite that I have not thought of? Basically I want to update three out of four columns if the record exists, If it does not exists I want to INSERT the record with the default (NUL) value for the fourth column. The ID is a primary key so there will only ever be one record to UPSERT. (I am trying to avoid the overhead of SELECT in order to determine if I need to UPDATE or INSERT obviously) Suggestions?  I cannot confirm that Syntax on the SQLite site for TABLE CREATE. I have not built a demo to test it, but it doesn't seem to be supported. If it was, I have three columns so it would actually look like: CREATE TABLE table1(      id INTEGER PRIMARY KEY ON CONFLICT REPLACE,      Blob1 BLOB ON CONFLICT REPLACE,      Blob2 BLOB ON CONFLICT REPLACE,      Blob3 BLOB  );  but the first two blobs will not cause a conflict, only the ID would So I assume Blob1 and Blob2 would not be replaced (as desired)  UPDATEs in SQLite when binding data are a complete transaction, meaning Each sent row to be updated requires:  Prepare/Bind/Step/Finalize statements unlike the INSERT which allows the use of the reset function The life of a statement object goes something like this:  Create the object using sqlite3_prepare_v2() Bind values to host parameters using sqlite3_bind_ interfaces. Run the SQL by calling sqlite3_step() Reset the statement using sqlite3_reset() then go back to step 2 and repeat. Destroy the statement object using sqlite3_finalize().  UPDATE I am guessing is slow compared to INSERT, but how does it compare to SELECT using the Primary key? Perhaps I should use the select to read the 4th column (Blob3) and then use REPLACE to write a new record blending the original 4th Column with the new data for the first 3 columns?
24071
I'm trying to understand Python's approach to variable scope. In this example, why is f() able to alter the value of x, as perceived within main(), but not the value of n?  def f(n, x):     n = 2     x.append(4)     print('In f():', n, x)  def main():     n = 1     x = [0,1,2,3]     print('Before:', n, x)     f(n, x)     print('After: ', n, x)  main()   Output:  Before: 1 [0, 1, 2, 3] In f(): 2 [0, 1, 2, 3, 4] After:  1 [0, 1, 2, 3, 4]
81341
I have table where one of the fields is JSON array. I need to append received JSON array into that field without overriding existing values.  Something like that:  CREATE OR REPLACE FUNCTION add_array(     array_received json[])   RETURNS void AS $BODY$      update table set _array_field = _array_field | array_received ...;  $BODY$   LANGUAGE plpgsql VOLATILE;
81559
Unfortunately, as a new user I am not allowed to comment. This is why I need to do a new post regarding to this topic:   This is my code in Google Sheets Script:  function onEdit(e) {   if (e.range.getSheet().getSheetName() == 'Tabellenblatt1' &amp;&amp; e.range.getColumn() == 1) {     e.range.offset(0,1).setValue(new Date());   } }   It works perfectly when I enter data in cell 1 manually, but when data is added via API (in this case when data is added via Zapier) it does not work. Anybody can give me a hint why?
25484
I have a MySQL table with coordinates, the column names are X and Y. Now I want to swap the column values in this table, so that X becomes Y and Y becomes X. The most apparent solution would be renaming the columns, but I don't want to make structure changes since I don't necessarily have permissions to do that.  Is this possible to do with UPDATE in some way? UPDATE table SET X=Y, Y=X obviously won't do what I want.    Edit: Please note that my restriction on permissions, mentioned above, effectively prevents the use of ALTER TABLE or other commands that change the table/database structure. Renaming columns or adding new ones are unfortunately not options.
95386
I have a CSV file that has many rows. I want to typeset these rows into a table using longtable and datatool package.     However just before before the "lastfoot" (which says concluded) I am getting an empty row which I do not want. How to remove that extra row?   The columns are not equally spaced under the dates. Somebody please help me to make them equally spaced.   I am giving the sample code. The name of my CSV file is namelist.csv and it looks like this.       number,degree,Name     1,Dr,Abdul Ali     2,Mrs,Francesca Joestar     3,Mr,Chan Ker Mei     4,Dr,Hikaru Yagami     5,Dr,Harish Kumar   My LaTeX code is below.  \documentclass[12pt]{article} \usepackage{setspace} \usepackage{bookman} \usepackage{longtable} \usepackage{pdflscape} \usepackage[a4paper,left=1in,right=0.8in,top=0.5in,bottom=0.5in]{geometry} \usepackage{tgschola} \usepackage{microtype} \usepackage{datatool} \DTLloaddb{names}{namelist.csv} %================================================================== \begin{document} % \begin{landscape} % \doublespacing % \begin{longtable}{|l|l|c|c|r|r|r|c|c|c|c|c|c|c|c|c|c|c|}\hline % No.&amp;\multicolumn{1}{c|}{Name}&amp; \multicolumn{2}{c|}{13.12.2010}&amp;   \multicolumn{2}{c|}{14.12.2010}&amp;\multicolumn{2}{c|}{15.12.2010}&amp; \multicolumn{2}{c|}{16.12.2010} &amp;\multicolumn{2}{c|}{17.12.2010}&amp;\multicolumn{2}{c|}{18.12.2010} &amp;\multicolumn{2}{c|}{19.12.2010} &amp;\multicolumn{2}{c|}{20.12.2010}\\ \hline\hline \endfirsthead % \multicolumn{18}{c}% {{\bfseries  Continued from previous page}} \\ \hline % No.&amp;\multicolumn{1}{c|}{Name}&amp; \multicolumn{2}{c|}{13.12.2010}&amp; \multicolumn{2}{c|}{14.12.2010}&amp;\multicolumn{2}{c|}{15.12.2010}&amp;  \multicolumn{2}{c|}{16.12.2010} &amp;\multicolumn{2}{c|}{17.12.2010}&amp;\multicolumn{2}{c|}{18.12.2010} &amp;\multicolumn{2}{c|}{19.12.2010} &amp;\multicolumn{2}{c|}{20.12.2010}\\ \hline\hline \endhead % \hline \multicolumn{18}{|r|}{{Continued on next page}} \\ \hline \endfoot % \hline \multicolumn{18}{|r|}{{Concluded}} \\ \hline \endlastfoot % \DTLforeach{names}{ \no=number, \dg=degree, \name=Name}{ \no&amp; \dg. \name &amp;  &amp; &amp;  &amp; &amp;  &amp; &amp;  &amp; &amp;  &amp;  &amp;  &amp;  &amp;  &amp;  &amp;  &amp; \\ \hline } \end{longtable}% % \end{landscape} % \end{document}
4188
While I was investigating a problem I had with lexical closures in Javascript code, I came along this problem in Python:  flist = []  for i in xrange(3):     def func(x): return x * i     flist.append(func)  for f in flist:     print f(2)   Note that this example mindfully avoids lambda. It prints "4 4 4", which is surprising. I'd expect "0 2 4".   This equivalent Perl code does it right:  my @flist = ();  foreach my $i (0 .. 2) {     push(@flist, sub {$i * $_[0]}); }  foreach my $f (@flist) {     print $f-&gt;(2), "\n"; }   "0 2 4" is printed.  Can you please explain the difference ?    Update:   The problem is not with i being global. This displays the same behavior:  flist = []  def outer():     for i in xrange(3):         def inner(x): return x * i         flist.append(inner)  outer() #~ print i   # commented because it causes an error  for f in flist:     print f(2)   As the commented line shows, i is unknown at that point. Still, it prints "4 4 4".
50860
I have a Shapefile with a lot of empty columns but many of them are empty. Using QGIS or ogr2ogr, how do I remove all attribute columns where everything is NULL?
19673
I am getting FATAL_ERROR|System.QueryException: List has no rows for assignment to SObject. I know that it is because it is not returning any rows in the SOQL query but what I want is that if it returns any row, it should update ALO field on contact object, if it is null then ALO field should be set to null.  Here is my code:  ziptoLOD = [SELECT Id, Name, LOD__c             FROM Zip_3_to_LOD__c             WHERE Name =: contact.Extract_Zipcode__c ];  Zip_3_to_LOD__c ziptoLOD2 = (ziptoLOD != null) ? ziptoLOD : null;  if (ziptoLOD2 == null) {     contact.ALO__c = ' ';    } else {     System.debug(System.LoggingLevel.ERROR, 'Zip to LOD' + ziptoLOD2);     contact.ALO__c = ziptoLOD2.LOD__c; }   My code gets stuck at the SOQL query and gives me the list has no rows error.