multiple-columns

How to use pandas to select certain columns in csv file

99封情书 提交于 2019-12-11 04:08:56
问题 I only just started my coding journey in order to and have watched a bunch of tutorials on youtube and am now trying to 'import' a dataset from SPSS into python using jupyter. So far I've managed to convert the .sav into a .csv file and read it using the code below. I want to select certain columns in my data and store them in a new csv file in order to do some analysis on them and try to build a script to predict certain things and characteristics. Problem is i have hundreds of data columns

Removing all the columns of the data frame that have same values across all the rows

丶灬走出姿态 提交于 2019-12-11 04:05:42
问题 I have a data frame like this : 1 NA 0.2 NA 1 2 2 NA 0.5 NA 1 6 3 NA 0.7 NA 1 4 4 NA 0.3 NA 1 4 I want to remove the columns that have same values across all the rows.i.e my data frame should look like this: 1 0.2 2 2 0.5 6 3 0.7 4 4 0.3 4 Is there an easiest way to do this? 回答1: dataf[sapply(dataf, function(x) length(unique(x))>1)] 来源: https://stackoverflow.com/questions/8776092/removing-all-the-columns-of-the-data-frame-that-have-same-values-across-all-the

Pandas, create columns after groupby

别等时光非礼了梦想. 提交于 2019-12-11 02:59:02
问题 Regarding the Pandas DataFrame 'test_df': id_customer id_order product_name 3 78 product1 3 79 product2 3 80 product3 7 100 product4 9 109 product5 After a groupby on 'id_customer' how is it possible to get: id_customer order_1 order_2 product_name_1 product_name_2 3 78 79 product1 product2 7 100 product4 9 109 product5 The goal is to retrieve the minimum between 2 and the number of line matching each 'id_customer' after the groupby, and then, if possible, fill all the above fields. I started

Python Pandas - n X m DataFrame multiplied by 1 X m Dataframe

最后都变了- 提交于 2019-12-11 02:27:40
问题 I am trying to multiply a 10X7 Pandas dataframe by a 1X7 dataframe in Python. Here is what I have: df = pd.DataFrame(np.random.rand(10,7),columns=list('ABCDEFG')) df_1 = pd.DataFrame(np.random.rand(1,7),columns=list('ABCDEFG')) I tried this: df_prod = pd.DataFrame(columns=df) for i in range(0, df.shape[0]): df_prod.iloc[i,:] = df[i,:].tolist()*df_1.iloc[0,:].tolist() But I get this error message: Traceback (most recent call last): File "C:\Python27\test.py", line 29, in <module> df_elem.iloc

Equal height columns width issue

亡梦爱人 提交于 2019-12-11 02:17:53
问题 I have 3 columns that extend to equal height. The only problem now is that if I have 2 columns only they expand their width and take 100% of the main container. So basically I need them to have the same width wether it's 1, 2 or 3 columns. Any idea on how to achieve this? Many thanks! Fiddle Demo .content > img { vertical-align:top; } #wrapper { height: 100%; width: 100%; margin: 20px auto; display:table; overflow: hidden; border-spacing: 30px; } #wrapper > .col { display: table-cell; width:

How to read column names of a multicolumn ListView control?

雨燕双飞 提交于 2019-12-11 02:12:55
问题 What is the best way to find the names of the columns of a ListView? I converted a DataTable to a List using a procedure I found on this forum, but I cannot make it to put the Id column first, especially because not all of my DataTables have a column "Id". I can search in collection listView.Columns.ToString() but the format I am seeing is: "ColumnHeader: Text: Id" which I have to parse to find the proper name "Id". This does not look like the spirit of C#. I also tried: listView

SQL Count. How can I count how many distinct values are in a table when an other two columns are matching?

China☆狼群 提交于 2019-12-11 02:04:59
问题 I am trying to complete an sql query to show how many GCSEs a student has on record.] *STUDENT *SUBJECT *SCHOOL ABB13778 | English | Social Care & Early Years ABB13778 | Information and Communication Technology | Social Care & Early Years ABB13778 | Mathematics | Social Care & Early Years ABB13778 | Media Studies | Social Care & Early Years For example this student should recieve a count of 4 as there is 4 distinct subjects assigned to the school and student ID. I can count the items but the

Evenly spaced fixed-width columns - in a responsive setting

£可爱£侵袭症+ 提交于 2019-12-10 23:24:21
问题 I'm trying to create some evenly spaced columns (an ol ), with the columns themselves being fixed width. So far, I've managed to achieve the desired effect by using table layout, and nesting an additional element inside the list item. HTML: <ol> <li><div></div></li> <li><div></div></li> <li><div></div></li> <li><div></div></li> <li><div></div></li> </ol>​ CSS: ol { display: table; width: 100%; } li { display: table-cell; } div { margin: 0 auto; width: 100px; height: 250px; } This works great,

Mutate multiple columns with a certain condition in R

二次信任 提交于 2019-12-10 23:15:11
问题 I have this data M1 M2 M3 UCL 1 2 3 1.5 I would like to make new columns with this condition: If M1 is more than UCL, MM1 will be "UP" and otherwise "NULL" If M2 is more than UCL, MM2 will be "UP" and otherwise "NULL" If M3 is more than UCL, MM3 will be "UP" and otherwise "NULL" M1 M2 M3 UCL | MM1 MM2 MM3 1 2 3 1.5 | NULL UP UP But I have several M column (like M1~M1005) so that I would like to make some code such as mutate_each and mutate_at. How do I use the function using mutate and ifelse

Java printf formatting to print items in a table or columns

◇◆丶佛笑我妖孽 提交于 2019-12-10 23:12:48
问题 I am wanting to print things in a neat columns using printf. happening 0.083333 [4] hi 0.083333 [0] if 0.083333 [8] important 0.083333 [7] is 0.250000 [3, 5, 10] it 0.166667 [6, 9] tagged 0.083333 [11] there 0.083333 [1] what 0.083333 [2] I have this code System.out.printf("%s %.6f %s \n", word, web.getFrequency(word), loc); , but it prints out this: happening 0.083333 [ 4 ] hi 0.083333 [ 0 ] if 0.083333 [ 8 ] important 0.083333 [ 7 ] is 0.250000 [ 3 5 10 ] it 0.166667 [ 6 9 ] tagged 0.083333