multiple-columns

Change all columns from factor to numeric in R

▼魔方 西西 提交于 2019-11-29 08:44:39
I am working with a big dataset that is causing some trouble because some of the columns I the dataset are being treated as factors. How can I convert all of the columns from factor to numeric, without having to do that column by column?? I have tried to apply a small loop, but it returns NA values. Here's a sample data that applies to the case: data <- structure(list(v1 = c(22.394, 43.72, 58.544, 56.877, 1.659, 29.142, 67.836, 68.851), v2 = c(144.373, 72.3, 119.418, 112.429, 35.779, 41.661, 166.941, 126.548), v3 = structure(c(33L, 29L, 33L, 5L, 13L, 31L, 5L, 8L), .Label = c("", "#VALUE!", "0"

Python - Calculate average for every column in a csv file

三世轮回 提交于 2019-11-29 07:55:33
I'm new in Python and I'm trying to get the average of every (column or row) of a csv file for then select the values that are higher than the double of the average of its column (o row). My file have hundreds of columns, and have float values like these: 845.123,452.234,653.23,... 432.123,213.452.421.532,... 743.234,532,432.423,... I've tried several changes to my code to get the average for every column (separately), but at the moment my code is like this one: def AverageColumn (c): f=open(csv,"r") average=0 Sum=0 column=len(f) for i in range(0,column): for n in i.split(','): n=float(n) Sum

Determine the Width of a dynamic CSS3 Multicolumn DIV width fixed column-width

一笑奈何 提交于 2019-11-29 06:37:07
I have a DIV container filled with a dynamic text. The length of the text can be different. The DIV container has a fixed height but no width. The Text is formatted as CSS3 Multicolumn Text width a fixed columns-width . The result is n columns with the width of column-width . Now i want to know either how many columns are there or how is the computed width of the DIV . CSS CODE: .columnize{ float: left; position: relative; width: 840px; overflow: hidden; } .columnize div{ -moz-column-width: 259px; -webkit-column-width: 259px; -moz-column-gap: 16px; -webkit-column-gap: 16px; height: 560px; }

How to merge/combine columns in pandas?

拥有回忆 提交于 2019-11-29 04:50:45
I have a (example-) dataframe with 4 columns: data = {'A': ['a', 'b', 'c', 'd', 'e', 'f'], 'B': [42, 52, np.nan, np.nan, np.nan, np.nan], 'C': [np.nan, np.nan, 31, 2, np.nan, np.nan], 'D': [np.nan, np.nan, np.nan, np.nan, 62, 70]} df = pd.DataFrame(data, columns = ['A', 'B', 'C', 'D']) A B C D 0 a 42.0 NaN NaN 1 b 52.0 NaN NaN 2 c NaN 31.0 NaN 3 d NaN 2.0 NaN 4 e NaN NaN 62.0 5 f NaN NaN 70.0 I would now like to merge/combine columns B, C, and D to a new column E like in this example: data2 = {'A': ['a', 'b', 'c', 'd', 'e', 'f'], 'E': [42, 52, 31, 2, 62, 70]} df2 = pd.DataFrame(data2, columns

Pandas dataframe - running sum with reset

心不动则不痛 提交于 2019-11-29 03:12:44
I want to calculate the running sum in a given column(without using loops, of course). The caveat is that I have this other column that specifies when to reset the running sum to the value present in that row. Best explained by the following example: reset val desired_col 0 0 1 1 1 0 5 6 2 0 4 10 3 1 2 2 4 1 -1 -1 5 0 6 5 6 0 4 9 7 1 2 2 desired_col is the value I want to be calculated. You can use 2 times cumsum() : # reset val desired_col #0 0 1 1 #1 0 5 6 #2 0 4 10 #3 1 2 2 #4 1 -1 -1 #5 0 6 5 #6 0 4 9 #7 1 2 2 df['cumsum'] = df['reset'].cumsum() #cumulative sums of groups to column des df[

Webkit CSS3 column adds an extra padding to its container.

百般思念 提交于 2019-11-29 02:57:21
问题 I've created a CSS3 multi column layout for image gallery which looks nice on Firefox. HTML : <section id="featured"> <article> <img src="http://sheepy.me/incoming/images/posts/blog/thumb_tim-burton-pokemans.png" /> </article> <article> <img src="http://sheepy.me/incoming/images/posts/blog/thumb_hem-tourniquet.png" /> </article> <article> <img src="http://sheepy.me/incoming/images/posts/blog/thumb_hem-tourniquet.png" /> </article> <article> <img src="http://sheepy.me/incoming/images/posts

Remove rows in python less than a certain value

帅比萌擦擦* 提交于 2019-11-29 02:48:56
问题 I feel like this question must have been answered by someone before, but I can't find an answer on stack overflow! I have a dataframe result that looks like this and I want to remove all the values less than or equal to 10 >>> result Name Value Date 189 Sall 19.0 11/14/15 191 Sam 10.0 11/14/15 192 Richard 21.0 11/14/15 193 Ingrid 4.0 11/14/15 This command works and removes all the values that are 10: df2 = result[result['Value'] != 10] But when I try to add the <= qualifier I get the error

Multicolumn ListBox in WPF

倖福魔咒の 提交于 2019-11-28 23:12:55
I have 3 TextBoxes and 1 Button and want to enter each of the the TextBoxes data into a ListBox in separate columns. I know how to enter data into one column: listbox1.Items.Add(TextBox1.text); but how can I enter the data into multiple columns? I am using .NET WPF. I want to use a ListBox or a ListView . my window Ray You want a ListView instead: Something like this: <ListView ItemsSource="{Binding SourceCollection}"> <ListView.View> <GridView> <GridViewColumn Header="Test1" DisplayMemberBinding="{Binding Test1}" /> <GridViewColumn Header="Test2" DisplayMemberBinding="{Binding Test2}" />

R subsetting a data frame into multiple data frames based on multiple column values

大兔子大兔子 提交于 2019-11-28 23:10:18
I am trying to subset a data frame, where I get multiple data frames based on multiple column values. Here is my example >df v1 v2 v3 v4 v5 A Z 1 10 12 D Y 10 12 8 E X 2 12 15 A Z 1 10 12 E X 2 14 16 The expected output is something like this where I am splitting this data frame into multiple data frames based on column v1 and v2 >df1 v3 v4 v5 1 10 12 1 10 12 >df2 v3 v4 v5 10 12 8 >df3 v3 v4 v5 2 12 15 2 14 16 I have written a code which is working right now but don't think that's the best way to do it. There must be a better way to do it. Assuming tab is the data.frame having the initial data

Half columns in Twitter Bootstrap 3

ぐ巨炮叔叔 提交于 2019-11-28 16:56:26
I couldn't figure out how to make the bootstrap column like this: col 3 | col 4.5 | col 4.5 You can try this : Just split a col-9 in 2 parts. Bootply : http://www.bootply.com/128927 HTML : <div class="col-xs-3"> col-xs-3 </div> <div class="col-xs-9"> <div class="row"> <div class="col-xs-6">col-xs-4.5</div> <div class="col-xs-6">col-xs-4.5 </div> </div> </div> 来源: https://stackoverflow.com/questions/22986664/half-columns-in-twitter-bootstrap-3