I am trying to access row index as a variable not as list nor anything else.
I tried different methods without success, can anyone be in anyway to help.
thanks,
ddo=df[(df.iloc[:,3]==4) & (df.iloc[:,5]==2) & (df.iloc[:,6]==2) & (df.iloc[:,15]>=0.02)]
starttime=ddo.iloc[0,1]
starttimerow=ddo.index[ddo.iloc[0,1]==starttime]
the expected output to be list not an array
array([[103971, 104031, 104090, 104149, 104209, 104269, 104327, 104385,
104445, 104503, 104562, 104621, 104680, 104737, 104797, 104856,
104914, 104973, 105032, 105091, 105149, 105209, 105267, 105326,
105384, 105443, 105502, 105561, 105620, 105679, 105738, 105796,
105855, 105914, 105972, 106032, 106091, 106150, 106209, 106268,
106326, 106385, 106444, 106502, 106562, 106621, 106680, 106739,
106798, 106856, 106915, 106974, 107032, 107092, 107151, 107210,
107269, 107328, 107386, 107445, 107505, 107565, 107627, 107688,
107751, 107813, 107875, 107935, 107998, 108059, 108120]],
dtype=int64)
I tried these lines
enddwellrow=df.loc[(ddo.iloc[:,1]==end_dwell)&(ddo.iloc[:,3]==4)].reset_index()
enddwell_idx=enddwellrow['index'][0]
Related
So I've been tring to use .index with 2D arrays just so I can do some tests on my code, but it just comes up with an error saying that the value which is in the list actually isn't.
For example, from one project (where i was trying to revise network layering whilst practicing some coding), I tried doing this but didnt work:
answers = [['Application Layer','HTTP','HTTPS','SMTP','IMAP','FTP'],['Transport Layer','TCP','UDP'],['Network Layer','ARP','IP','ICMP'],['Data Link layer']]
correct = 0
incorrect = 0
qs = answers[randint(0,3)][0]
print(answers.index(qs))
print(qs)
Example from code
As you can see, I'm trying to get back the value of 'qs' by using index but no luck.
I've seen a few other posts saying to use numpy, but how would I do this without using numpy?
You can do it like this.
answers = [['Application Layer','HTTP','HTTPS','SMTP','IMAP','FTP'],['Transport Layer','TCP','UDP'],['Network Layer','ARP','IP','ICMP'],['Data Link layer']]
correct = 0
incorrect = 0
qs = answers[randint(0,3)][0]
for i, answer in enumerate(answers):
if qs in answer:
print(i)
break
print(qs)
I'm beginner at Python and Pandas.
I have origin Data what i defined F1 and shape (194000,4).
I wanna split it into 97 groups of 2,000 each (ex. Index num 0~1999 is F1_0, 2000~3999 is F1_1)
And i wrote code like below.
n=0
for i in (0, 97):
num=2000*(i+1)
globals()['F1_{0}'.format(i)] = F1.loc[n:num]
n = A
When i call F1_0, there is no problem.
But From F1_1 to F1_96, there is "no define error".
I don't know what's the reason in my code :(
And i'd appreciate if you could let me know if there is better way.
Thanks for reading
Using range instead of only passing a tuple in the loop. In your code, for loop will iterates the value 0 and 97 only, not the range (0, ..., 96).
n=0
for i in range(97):
num=2000*(i+1)
globals()['F1_{0}'.format(i)] = F1.loc[n:num]
I hope I can be as clear as possible.
I have an excel file with 400 subjects for a study and for each one of them I have their age, their sex and 40 more columns of biological variables.
Es: CODE0001; (age)20; M\F; Biovalue1; BioValue 2 ..... Biovalue 40.
My goal is to analyze these data with the 1-way Anova because I think it's the best option I have. I'm trying do it (even using this guide https://www.marsja.se/four-ways-to-conduct-one-way-anovas-using-python/ ) but there's always a problem with the code.
So: how can I set up my data in order to be able to use the code for example from that website?
I've already done Dataset.mean() and Dataset.std() for all the data, but I can't use for example the value "Mean Age" because it seems like Jupyter only reads it as a string and not a value.
I'm in a deep state of confusion, so all kind of help will be super appreciated!!!
Thank you in advance
I'm sorry but I didn't understand. I'm relatively new to python so maybe i couldn't explain myself properly.
I need to do an Anova analysis:
First I did this:
AnalisiISAD.mean()
2) Then I made a list from that:
MeanList = [......]
3) Then i proceded with the anova script
AnalisiI.boxplot('MeanList', by='AgeT0', figsize=(12,8))
ctrl = Analisi['MeanList'][Analisi == 'ctrl']
grps = pd.unique(Analisi.group.values)
d_data = {grp:Analisi['MeanList'][Analisi.group ==grp] for grp in grps}
k = len(pd.unique(Analisi.group))
N = len(Analisi.values)
n = Analisi.groupby('AgeT0').size()[0]
but this error occurs: KeyError: 'Column not found: MeanList'
Does this mean I have to create a new column in the excel file? How do I do that?
When using df.mean() or df.std(), try changing the data to pd.Series first and run it.
input text image
I am using the below code to convert the columns to rows in the text.
My requirement is to find the count of each character in each column in the text
b=[''.join(i) for i in zip(*a2.split())]
print(b)
I am getting below input
['CCACTCGT', 'GTGGCCCC', 'AGCACTGC', 'CCTGCAGA', 'TTTAACCA', 'CGTACCTC', 'CACCCCCA', 'CGCCCCTT', 'GCTCCATG', 'CCAAAGGA', 'GCTCGCCT', 'ACTCACCC', 'ATCCTGGG', 'GGAACGCT', 'ACATCCTG', 'CGGCTTGC', 'TCAACCCG', 'TACGCGTT', 'GTCATCGT', 'ACAGAACC', 'CCCCCCTC', 'CACCCTGT', 'CACTTCCG', 'CGACTTCC', 'AGCCTCGA', 'AACCTGCA', 'ACTTCGTG', 'GCCTTCGT', 'CCTCGTCG', 'TTGCGGTC', 'CTGAGTGA', 'GCTCGGTG', 'GTACACGC', 'GCCTGCGT', 'CGCCAGCG', 'GGATCGTA', 'CAGGCGGG', 'ATACCGCG', 'CCTTCGTC', 'CCCCTGAC', 'CGTCCCGC', 'CGCTAGTC', 'CGGCGCGG', 'CACCCCCC', 'TGCGCGTC', 'GACTCCGC', 'CCATCCAC', 'AGTCTTCG', 'CGCTGCGC', 'AATCTCCC', 'CACCACCC', 'TTGCGCTA', 'TCGTGCGC', 'CTTGGAGA', 'CGTAGTCG', 'CTTGCGCC', 'CCTAGCGC', 'ATTGGCGC', 'CCTCGGCC', 'TACCGCCG', 'CGCTCCGC', 'TAGCCTGC', 'CCTATTCC', 'ACAACCCA', 'GTGCCGGC']
You can see the last 5 columns in the text are not coming in the list.
Iam not able to figure it out why this is happening.Any help would be highly appreciated.
Also please suggest if there is any other way to achieve the same result.
zip returns as many tuples as there are items in the shortest iterable, so only full columns are returned. To get all columns you can use zip_longest, like this:
from itertools import zip_longest
b = [''.join(i) for i in zip_longest(*a2.split(), fillvalue='')]
i am trying to use this program to get a list (phi0ex) of 211 arrays each array contains 251*251 elements
all what i get is a list of arrays of 251 elements, please help
data=loadtxt('data.csv',delimiter=',')
data1=data.transpose()
ngrains=loadtxt('nombre_grain.csv',delimiter=',')
phi0ex1=211*[zeros(shape(251*251))]
gr1=zeros(shape=(251,251))
for k in range(0,len(ngrains)):
for i,j in enumerate(data1):
for s in range(0,251):
gr1[i]=where(s==ngrains[k],1,0)
phi0ex1[k]=gr1
print phi0ex1
#
i found the solution thank you guys for showing intrest, accully the function where() do the iteration it self (that i did'nt know) there is no need to put it in an other loop, only the loop over "ngrains will do the trick.
data=loadtxt('data.csv',delimiter=',')
data1=data.transpose()
ngrains=loadtxt('nombre_grain.csv',delimiter=',')
phi0ex=len(ngrains)*[zeros(shape(250))]
for k in range(len(ngrains)):
print ngrains[k]
phi0ex[k]=where(data1==ngrains[k],1,0)
print phi0ex