I’m using a FEM software (Code_Aster) which is developed in Python, but its file extension is .comm. However, Python snippets can be inserted in .comm files. I have a function which returns a very long string containing nodes, elements, elements group, and so on in the below form: My goal is to add each…
Tag: python
Indexing 2d lists in Python: Lengths in each dimension are not what I expect
If I create a 2d list: I would expect the list in the first element of foo to be accessed with foo[0] or foo[0][:]. Thus it’s length is 10, as expected: type(foo[:][0]) returns “list”. I would expect this to be a list constructed of the 0th elements from each “sublist” of foo. Th…
Assign outcome from SQL query to column
I have a dataframe (test_df) that looks like this: I want to assign the result from executing the query in dq_sql to the column Results. I tried this: which results in: Strange thing is, the ‘X’ result should be assigned to row 1, whereas the query in row 0 does not seem to run. When I try to run …
How to write an object typed array into csv file with NumPy?
I have two numpy arrays(A, B) and 2 scalar values(C,D) that I want to store in a csv file. I know how to write a single numpy array in it: I want the first two columns of my csv-file to contain the 2 arrays A and B and then have the 2 scalar values C and D as the first
Store the contents of text file in return variable and manipulate wherever required in python?
I have below function & I am trying to get/store the contents of text file in another temp file(removing unnecessary line) with appending special character. But I also want the same content which is in temp text file with different special character next time but I am not able to do that.Below function is…
Python: convert dictionary into a cvs file
This is my current code: What I am trying to achieve is that the dictionary keys are turned into the csv headers and the values turned into the rows. But when running the code I get a TypeError: ‘string indices must be integers’ in line 21. Answer Problem The issue here is for row in data. This is…
an alternative to (any) function
I’m currently working on a password validity code, but I didn’t learn the (any) function yet so I should not use it I’m looking for a different way to make the code work and check if there is lowercase, uppercase, and digits in the password. I thought about using a loop that checks each char…
Divide a list by elements of another list
I want to divide a list error_variance_vector by an element in another list sigma_square1, such that it gives corresponding W element (w_i). Here’s my attempt: but I got an error message: Answer This should work:
Pandas: how select row based on string in previous row – should be a simple solution
I have a a csv file. How do I print the row that follows a row that has a particular string? I need to print all rows that contain “ixation” in them and then the row that follows this row. Here is my current code Here is my current output… But I want… How do I only print out the
python seaborn plotting using index when index has some missing values
I have a dataframe as below. Index is blank for some rows. I want to plot it and my code is as below i am struggling with marker It is appearing only for few points – how could i show all the points? How could I rotate x axis labels. I tried the last line that i have commented. lst