I have the following problem:
Objective (high-level):
I would like to convert ESRI Shapefiles into SQL spatial data. For that purpose, I need to adapt the synthax.
Current status / problem:
I constructed a the following cell array:
'MULTIPOLYGON(' {1x2332 cell} ',' {1x916 cell} ',' {1x391 cell} ',' {1x265 cell} ')'
with in total 9 fields. This cell array contains the following 'nested' cell arrays: {1x2332 cell}, {1x916 cell}, {1x391 cell}, {1x265 cell}. As an example, 'nested' cell {1x2332 cell} has the following form:
'((' [12.714606000000000] [42.155628000000000] ',' [12.702529999999999] [42.152873999999997] ',' ... ',' [12.714606000000000] [42.155628000000000] '))'
However, I would like to have the entire cell array (including all 'nested cells') as one string without any spaces (except the space between the numbers (coordinates)). Would you have an idea how I could get to a solution?
Thank you in advance.
You probably need loops for this.
Consider a smaller example:
innerCell1 = {'((' [12.714606000000000] [42.155628000000000] ',' [12.702529999999999] [42.152873999999997] ',' [12.714606000000000] [42.155628000000000] '))'};
outerCell = {'MULTIPOLYGON(' innerCell1 ',' innerCell1 ')'};
You can go along these lines:
outer = outerCell; %// will be overwritten
ind_outer = find(cellfun(#iscell, outer)); %// positions of inner cell arrays in `outer`
for m = ind_outer
inner = outer{m};
ind_inner = cellfun(#isnumeric, inner); %// positions of numbers in `inner`
ind_inner_space = find(ind_inner(1:end-1) & ind_inner(2:end)); %// need space
ind_inner_nospace = setdiff(find(ind_inner), ind_inner_space); %// don't need
for n = ind_inner_space
inner{n} = [num2str(inner{n}) ' ']; %// convert to string with space
end
for n = ind_inner_nospace
inner{n} = num2str(inner{n}); %// convert to string, without space
end
outer{m} = [inner{:}]; %// concatenate all parts of `inner`
end
str = [outer{:}]; %// concatenate all parts of `outer`
This results in the string
str =
MULTIPOLYGON(((12.7146 42.1556,12.7025 42.1529,12.7146 42.1556)),((12.7146 42.1556,12.7025 42.1529,12.7146 42.1556)))
Related
there is a list which contains integer values.
list=[1,2,3,.....]
then I use np.random.choice function to select a random element and add it to the a existing dataframe column, please refer to below code
df.message = df.message.astype(str) + "rowNumber=" + '"' + str(np.random.choice(list)) + '"'
But the element selected by np.random.choice and appended to the message column are always the same for all message row.
What is issue here?
Expected result is that the selected element from the list is not the same.
Pass to np.random.choice with parameter size and convert values to strings:
df = pd.DataFrame(
{'message' : ['aa','bb','cc']})
L = [1,2,3,4,5]
df.message = (df.message.astype(str) + "rowNumber=" + '"' +
np.random.choice(L, size=len(df)).astype(str) + '"')
print (df)
message
0 aarowNumber="4"
1 bbrowNumber="2"
2 ccrowNumber="5"
I made a dataframe from a dictionary and set one of its columns as my index. While inserting new a row, I get this error:
docdf=docdf.loc[sno_value]=[name_value,age_value,special_value,contact_value,fees_value,sal_value]
AttributeError: 'list' object has no attribute 'loc'
This is my code:
import pandas as pd
dict={"S.NO":[1,2,3,4,5],
"NAME":["John Sharon","Steven Sufjans","Ram Charan","Krishna Kumar","James Chacko"],
"AGE":[30,29,44,35,45],
"SPECIALISATION":["Neuro","Psych","Cardio","General","Immunology"],
"CONTACT":[9000401199,9947227405,9985258207,9982458204,8976517744],
"FEES":[1200,2100,3450,4500,3425],
"SAL":[20000,30000,40000,50000,45800]}
docdf=pd.DataFrame(dict)
docdf= docdf.set_index("S.NO")
#INSERT A ROW
sno_value=int(input('S.NO: '))
name_value = input('NAME: ')
age_value = int(input('AGE: '))
special_value = input('SPECIALISATION: ')
contact_value = int(input('CONTACT: '))
fees_value = int(input('FEES: '))
sal_value = int(input('SAL: '))
docdf=docdf.loc[sno_value]=[name_value,age_value,special_value,contact_value,fees_value,sal_value]
print(docdf)
I tried inserting each value separately and then tried to insert a new row using loc function. I was expecting the input S.NO to become the index of new row and then print the whole dictionary with the new row.
i am trying to ltrim 3 or 4 zeros from a column in Access 2007 but not getting any result where the data-type is text(from a csv data).
From what I read, MS Access in fact should support LTRIM. Here is a workaround in case you need it:
SELECT
IIF(string LIKE "0000*",
MID(string, 5),
IIF(string LIKE "000*", MID(string, 4), string)) output
FROM yourTable;
Here are a couple of quickly written LTrim & RTrim functions to operate with characters other than spaces:
Function LTrimChr(strStr As String, strChr As String) As String
If strStr Like strChr & "*" Then
LTrimChr = LTrimChr(Mid(strStr, 2), strChr)
Else
LTrimChr = strStr
End If
End Function
Function RTrimChr(strStr As String, strChr As String) As String
If strStr Like "*" & strChr Then
RTrimChr = RTrimChr(Left(strStr, Len(strStr) - 1), strChr)
Else
RTrimChr = strStr
End If
End Function
Expects the strChr to be a single character, e.g.:
?LTrimChr("000123456789000","0")
123456789000
?RTrimChr("000123456789000","0")
000123456789
In case of digits only, you can use Val to strip leading zeroes:
LTrimmedValue = CStr(Val(Value))
' "000123456789000" -> "123456789000"
MS Access supports ltrim(), but only for spaces. So, assuming that your string has no spaces, you can use replace() and ltrim():
select replace(ltrim(replace(col, '0', ' ')), ' ', '0')
If you do have spaces, there is often a character you don't have, so you can replace the spaces first:
select replace(replace(ltrim(replace(replace(col, ' ', '~'
), '0', ' '
)
), ' ', '0'
), '~', ' '
)
I am manipulating strings.
I want the output string to be only between 2 specific characters (= and o)
I can do this by repeat this twice:
For f = 1 To Len(line5)
If Mid(line5, f, 1) = "=" Then
line5 = Mid(line5, f, Len(line5) - f + 1)
line5 = line5_out
End If
One time for = and one for o
Is there a quicker way to do this?
There are multiple ways to do it, the "best" way depends on what exactly you need.
Besides those comments, here are two more ways to do it:
'Delete everything behind o and infront of =
YourString = YourString.Remove(YourString.LastIndexOf("o") + 1, YourString.Length - YourString.LastIndexOf("o") - 1).Remove(0, YourString.IndexOf("="))
'Get part of string between = and o
YourString = YourString.Substring(IndexOf("="), YourString.LastIndexOf("o") + 1 - YourString.IndexOf("="))
I am making pattern for my strings in database here is my needs:
I have to iterate through each record and then I have to check its every character of string using SQL
After that I have to concatenate the string and show like that:
//DECLARING STRINGS IN VARIABLES
SET #str = '4444--6699p'
SET #CHS = '%[a-z]'
SET #CHE = '[a-z]'
SET #CHE2 = '[a-z]%'
SET #NUMS = '%[0-9]'
SET #NUME = '[0-9]'
SET #NUME2 = '[0-9]%'
SET #CHR = '-'
//GET THE IDENT OF SLASH
SET #INDENT = (SELECT PATINDEX('%-%', #str));
// CHECH CONTAIN CHARECTER OR NOT
IF PATINDEX('%[a-z]%' , #str) > 0
//BUILT STRING TILL INDENT
SET #CHA = #CHS
while #id <= #INDENT
begin
set #id = #id + 1
SET #CHA = #CHA + #CHE
end
SET #CHA = #CHA + #CHE2
print #CHA
end
//IF NO CHARECTER BUILT HERE
ELSE
print #NUMS + #NUME + #NUME2
but no want to concate string in that this is a pattern but here is explaination
have a look at database strings now
// DATABASE EXAMPLES OF STRING
(512) 482-2392
(518) 457-5181
http://www.menupages.com/restaurants/cafe-shane/
https://www.google.com/#q=auto
025-121-3453
429–432–2145
there expression returned as for 1 if record exist 3 times or more other wise null
(%[0-9][0-9][0-9]%) [0-9][0-9][0-9] - [0-9][0-9][0-9][0-9]
expressions can be like that abcz-aaassss-ccv so [a-z]{0,3}-[a-z]{0,10}-[a-z]{0,3}
HINT:
As in case of c sharp we do
string builtme;
builtme = builtme + builtme;
ACHEIVEMENT
HERE IS OUT PUT EXAMPLE
%[a-z][a-z][a-z]% - %[a-z][a-z][a-z][a-z]%-%[a-z][a-z][a-z]%