python: remove comboBox items in a loop manner [duplicate] - pyqt

This question already has answers here:
Python: Removing list element while iterating over list [duplicate]
(9 answers)
List "quirk" in python
(4 answers)
Closed 12 months ago.
I tried to delete all comboBox items using a loop as follow:
for idx in range(comboBox.count()):
print(idx, comboBox.count()) # show the loop number and check how many items left each loop
comboBox.removeItem(idx)
However, still 2 items left after the looping through all items instead of clearing them all out.
The prints are as following.
0 5
1 4
2 3
3 2
4 2
5 2
So it went haywire after 3. Why is this happening?

Related

How to select first row after each 3 rows pandas [duplicate]

This question already has answers here:
Pandas every nth row
(7 answers)
Closed 1 year ago.
I have one dataframe, i want to get first row of each 3 rows in dataframe and save new dataframe
here is input data
df=pd.DataFrame({'x':[1,2,5,6,7,8,9,9,6]})
output:
df_out=pd.DataFrame({'x':[1,6,9]})
Use DataFrame.iloc with slicing:
print (df.iloc[::3])
x
0 1
3 6
6 9

Un-merge a dataframe based on a column [duplicate]

This question already has answers here:
How to unnest (explode) a column in a pandas DataFrame, into multiple rows
(16 answers)
Split (explode) pandas dataframe string entry to separate rows
(27 answers)
Closed 2 years ago.
I am reading a csv file into a pandas dataframe and the data inside dataframe is as below:
item seq_no db_xml
0 28799179 5 ['<my_xml>....</my_xml>']
1 28839888 1 ['<my_xml>....</my_xml>']
2 28840113 75 ['<my_xml>....</my_xml>']
3 28852466 20,22 ['<my_xml1>....</my_xml1>', '<my_xml2>....</my_xml2>']
I need to convert above dataframe as below i.e. each seq_no for same item and its db_xml should be in different rows. I need to unmerge seq_no of same item in subsequent rows.
item seq_no db_xml
0 28799179 5 ['<my_xml>....</my_xml>']
1 28839888 1 ['<my_xml>....</my_xml>']
2 28840113 75 ['<my_xml>....</my_xml>']
3 28852466 20 ['<my_xml1>....</my_xml1>']
4 28852466 22 ['<my_xml2>....</my_xml2>']
Please let me know on how to achieve the same in pandas so that even seq_no is also split and in separate rows?

dropna() not working for axis = 1 with the given threshold [duplicate]

This question already has answers here:
thresh in dropna for DataFrame in pandas in python
(3 answers)
Closed 2 years ago.
For the given dataset
I performed a dropna on axis = 1 with threshold = 2
df.dropna(thresh=2,axis=1)
The output was
Which does not seem correct, what I expect is to drop column with index = 1 and 2 given that both columns have NaN occurences >= 2
The code works perfectly fine with axis=0
Try using df.dropna(thresh=6,axis=1) for same dataframe.

Problem with multiidimentional input to loop and list

First time asking in the forum.
I have a problem.
I have to loop thru a vertical list like this.
1
2
3
4
5
6
7
8
9
10
11
Each separated by enter key, not by space. And then reorganize each item/number descending.
For the descending organization i already know it can be sorted or sorted reverse. But for all I have tried I cannot loop thru all the items in the vertical list.
It only reads 1 and ends the cycle which I understand it is only reading the first list but I just do not know how to loop thru vertical lists be it 1 single value or a matrix.
This is my code
from pip._vendor.distlib.compat import raw_input
numbers = raw_input()
line = []
for row in numbers:
line.append(row)
print(line)
line.sort(reverse=True)
for value in line:
print(value)
input:
1
2
3
4
5
6
7
8
9
10
11
Once again each separated by enter key, not by space
output:
['1']
Thanks in advance for your support.

python dataframe - grouping rows [duplicate]

This question already has answers here:
Pandas: groupby column A and make lists of tuples from other columns?
(4 answers)
Closed 3 years ago.
I'm new to python so the question might not be so clear.
I have this dataset with pandas dataframe that goes something like this.
Id item
0 A0029V93 B0239WN
1 A0029V93 B0302SS
2 A02948s8 B0029ST
...
and the result I want is
Id item
0 A0029V93 (B0239WN,B0302SS)
1 A02948s8 (B0029ST, ...)
2 ... ...
...
No duplicate Id and all the items in the data paired with the ID
It doesn't necessarily have to look like this
as long as I can get the Id,[item] data.
df.groupby('Id')['item'].apply(list)

Resources