row

Pandas: how to convert a cell with multiple values to multiple rows?

点点圈 提交于 2019-12-20 14:13:13
问题 I have a DataFrame like this: Name asn count Org1 asn1,asn2 1 org2 asn3 2 org3 asn4,asn5 5 I would like to convert my DataFrame to look like this: Name asn count Org1 asn1 1 Org1 asn2 1 org2 asn3 2 org3 asn4 5 Org3 asn5 5 I know used the following code to do it with two columns, but I am not sure how can I do it for three. df2 = df.asn.str.split(',').apply(pd.Series) df2.index = df.Name df2 = df2.stack().reset_index('Name') Can anybody help? 回答1: Carrying on from the same idea, you could set

Programmatically assigning a color to a row in DataGrid

人盡茶涼 提交于 2019-12-20 11:32:24
问题 I need to assign a color to the row I add at runtime to the DataTable. How can this be done? 回答1: You can handle the DataGrid's LoadingRow event to detect when a row is being added. In the event handler you can get a reference to the DataRow that was added to the DataTable that is acting as your ItemsSource. Then you can update the DataGridRow's color however you like. void dataGrid_LoadingRow(object sender, Microsoft.Windows.Controls.DataGridRowEventArgs e) { // Get the DataRow corresponding

How To Find The Table Names Which Are Locked (Specific to any transaction)

白昼怎懂夜的黑 提交于 2019-12-20 09:45:08
问题 Is there any way to list out the locked tables and to kill the transactions if we want them to be unlocked immediately. Or is there any other terminology do we need to follow for above operation i am seeking for. Any Help or guidance will be appreciated. 回答1: This will show all databases with exclusive locks being held (which may include transient ones held at the time this is run), using the sys.dm_tran_locks DMV: select d.*, l.* from sys.dm_tran_locks l join sys.databases d on l.resource

How to set row height of QTableView?

萝らか妹 提交于 2019-12-20 08:59:14
问题 I have QTableView and QAbstractTableModel . I require rows to have height equal to 24. I know the only way to do this is by calling QTableView::setRowHeight . Since the model is dynamic it may be added new rows, but I don't want to call setRowHeight each time new row is added. How can I configure QTableView such that it uses the same height for new added rows or can a model be sent the height of rows? 回答1: For Qt versions < 5 QHeaderView *verticalHeader = myTableView->verticalHeader();

Subtracting group specific value from rows in pandas

徘徊边缘 提交于 2019-12-20 07:59:01
问题 In Pandas I have a data frame consisting of two groups with several samples in each group. Each group has an internal reference value that I want to subtract from all the sample values within that group. s = u"""Group sample value group1 ref1 18.1 group1 smp1 NaN group1 smp2 20.3 group1 smp3 30.0 group2 ref2 16.1 group2 smp4 29.2 group2 smp5 19.9 group2 smp6 28.9 """ df = pd.read_csv(io.StringIO(s), sep='\s+') df = df.set_index(['Group', 'sample']) df Out[82]: value Group sample group1 ref1

Convert selected column values to another row using select with the same id part2 [closed]

一曲冷凌霜 提交于 2019-12-20 07:51:23
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago . I am making a simple time in and time out system.. i have 3 pairs of in and outs. p_id(person_id) TableA p_id time_id status timestamp 1 1 in 2013-12-18 15:44:09 2 2 in 2013-12-18 16:23:19 1 3 out 2013-12-18 18:31:11 1 4 in 2013-12-18 18:50:11 3 5 out 2013-12-18 19:20:16 1 6 out 2013-12-18 19:50:11

Drop row based on two columns conditions

浪尽此生 提交于 2019-12-20 06:18:57
问题 I have dataframe looks like this: df Data1 Data2 Data3 A XX AA A YY AA B XX BB B YY CC C XX DD C YY DD D XX EE D YY FF I want to delete all the row (column data3) based on two columns (data1 and data2) with the condition if the data on data3 is same the delete. my expected result looks like this: Data1 Data2 Data3 B XX BB B YY CC D XX EE D YY FF how to do it? 回答1: Using groupby + transform with nunique yd=df[df.groupby(['Data1']).Data3.transform('nunique').gt(1)].copy() Out[506]: Data1 Data2

Delete row if cells equal a set of values

笑着哭i 提交于 2019-12-20 06:17:03
问题 I created a macro to in order to generate a daily report. The portion of the macro that finds a value in column AN and deletes the entire row (code edited to delete rows starting from the last used row), works well. The following example deletes all the rows that do not contain the value "CAT","BAT", or "DOG in column AN. 'False screen updating Application.ScreenUpdating = False 'deleting all other types other than CAT from "samples" tab (excluding the header row, row 1) Sheets("sample")

Remove Blank ROWS from CSV files in php

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 05:21:57
问题 Is it possible to remove all blank ROWS from a CSV file? I'm trying to count all rows from a CSV file but would like to exclude lines that doesn't contain a value on a specific column or the whole row. This is what I'm using to count the rows as of the moment. $import = file($target_path, FILE_SKIP_EMPTY_LINES); $num_rows = count($import); echo $num_rows; sample: Jun,Bronse,137 Raven,Princeton,TX,75407,2147088671,Nell@Gmail.Com,1990,CHEVROLET,K1500,, ,,,,,,,,,,,, ,,,,,,,,,,,, ,,,,,,,,,,,,

How to give each instance its own row in a data frame? [duplicate]

强颜欢笑 提交于 2019-12-20 05:02:31
问题 This question already has answers here : Repeat each row of data.frame the number of times specified in a column (7 answers) Closed last month . How is it possible to transform this data frame so that the count is divided into separate observations? df = data.frame(object = c("A","B", "A", "C"), count=c(1,2,3,2)) object count 1 A 1 2 B 2 3 A 3 4 C 2 So that the resulting data frame looks like this? object observation 1 A 1 2 B 1 3 B 1 4 A 1 5 A 1 6 A 1 7 C 1 8 C 1 回答1: rep(df$object, df$count