columnname

Using variable value as column name in data.frame or cbind

本小妞迷上赌 提交于 2019-11-27 22:58:44
Is there a way in R to have a variable evaluated as a column name when creating a data frame (or in similar situations like using cbind)? For example a <- "mycol"; d <- data.frame(a=1:10) this creates a data frame with one column named a rather than mycol . This is less important than the case that would help me remove quite a few lines from my code: a <- "mycol"; d <- cbind(some.dataframe, a=some.sequence) My current code has the tortured: names(d)[dim(d)[2]] <- a; which is aesthetically barftastic. > d <- setNames( data.frame(a=1:10), a) > d mycol 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 Is

DataGridView Edit Column Names

拈花ヽ惹草 提交于 2019-11-27 17:57:23
问题 Is there any way to edit column names in a DataGridView? 回答1: I don't think there is a way to do it without writing custom code. I'd implement a ColumnHeaderDoubleClick event handler, and create a TextBox control right on top of the column header. 回答2: You can also change the column name by using: myDataGrid.Columns[0].HeaderText = "My Header" but the myDataGrid will need to have been bound to a DataSource . 回答3: You can edit the header directly: dataGridView1.Columns[0].HeaderCell.Value =

pandas assign with new column name as string

折月煮酒 提交于 2019-11-27 13:41:43
问题 I recently discovered pandas "assign" method which I find very elegant. My issue is that the name of the new column is assigned as keyword, so it cannot have spaces or dashes in it. df = DataFrame({'A': range(1, 11), 'B': np.random.randn(10)}) df.assign(ln_A = lambda x: np.log(x.A)) A B ln_A 0 1 0.426905 0.000000 1 2 -0.780949 0.693147 2 3 -0.418711 1.098612 3 4 -0.269708 1.386294 4 5 -0.274002 1.609438 5 6 -0.500792 1.791759 6 7 1.649697 1.945910 7 8 -1.495604 2.079442 8 9 0.549296 2.197225

Pandas index column title or name

核能气质少年 提交于 2019-11-27 05:53:22
How do I get the index column name in python pandas? Here's an example dataframe: Column 1 Index Title Apples 1 Oranges 2 Puppies 3 Ducks 4 What I'm trying to do is get/set the dataframe index title. Here is what i tried: import pandas as pd data = {'Column 1' : [1., 2., 3., 4.], 'Index Title' : ["Apples", "Oranges", "Puppies", "Ducks"]} df = pd.DataFrame(data) df.index = df["Index Title"] del df["Index Title"] print df Anyone know how to do this? You can just get/set the index via its name property In [7]: df.index.name Out[7]: 'Index Title' In [8]: df.index.name = 'foo' In [9]: df.index.name

Pandas index column title or name

不羁的心 提交于 2019-11-26 06:55:56
问题 How do I get the index column name in python pandas? Here\'s an example dataframe: Column 1 Index Title Apples 1 Oranges 2 Puppies 3 Ducks 4 What I\'m trying to do is get/set the dataframe index title. Here is what i tried: import pandas as pd data = {\'Column 1\' : [1., 2., 3., 4.], \'Index Title\' : [\"Apples\", \"Oranges\", \"Puppies\", \"Ducks\"]} df = pd.DataFrame(data) df.index = df[\"Index Title\"] del df[\"Index Title\"] print df Anyone know how to do this? 回答1: You can just get/set