dataframe

plot dataframe with two y-axes

ⅰ亾dé卋堺 提交于 2021-02-20 06:16:57
问题 I have the following dataframe: land_cover 1 2 3 4 5 6 size 0 20 19.558872 6.856950 3.882243 1.743048 1.361306 1.026382 16.520265 1 30 9.499454 3.513521 1.849498 0.836386 0.659660 0.442690 8.652517 2 40 10.173790 3.123167 1.677257 0.860317 0.762718 0.560290 11.925280 3 50 10.098777 1.564575 1.280729 0.894287 0.884028 0.887448 12.647710 4 60 6.166109 1.588687 0.667839 0.230659 0.143044 0.070628 2.160922 5 110 17.846565 3.884678 2.202129 1.040551 0.843709 0.673298 30.406541 I want to plot the

plot dataframe with two y-axes

懵懂的女人 提交于 2021-02-20 06:16:18
问题 I have the following dataframe: land_cover 1 2 3 4 5 6 size 0 20 19.558872 6.856950 3.882243 1.743048 1.361306 1.026382 16.520265 1 30 9.499454 3.513521 1.849498 0.836386 0.659660 0.442690 8.652517 2 40 10.173790 3.123167 1.677257 0.860317 0.762718 0.560290 11.925280 3 50 10.098777 1.564575 1.280729 0.894287 0.884028 0.887448 12.647710 4 60 6.166109 1.588687 0.667839 0.230659 0.143044 0.070628 2.160922 5 110 17.846565 3.884678 2.202129 1.040551 0.843709 0.673298 30.406541 I want to plot the

Pandas count values inside dataframe

≡放荡痞女 提交于 2021-02-20 05:00:32
问题 I have a dataframe that looks like this: A B C 1 1 8 3 2 5 4 3 3 5 8 1 and I want to count the values so to make df like this: total 1 2 3 2 4 1 5 2 8 2 is it possible with pandas? 回答1: With np.unique - In [332]: df Out[332]: A B C 1 1 8 3 2 5 4 3 3 5 8 1 In [333]: ids, c = np.unique(df.values.ravel(), return_counts=1) In [334]: pd.DataFrame({'total':c}, index=ids) Out[334]: total 1 2 3 2 4 1 5 2 8 2 With pandas-series - In [357]: pd.Series(np.ravel(df)).value_counts().sort_index() Out[357]:

Delete rows from pandas dataframe if all its columns have empty string

北城余情 提交于 2021-02-20 04:22:31
问题 I have a dataframe as follows Name Age 0 Tom 20 1 nick 21 2 3 krish 19 4 jack 18 5 6 jill 26 7 nick Desired output is Name Age 0 Tom 20 1 nick 21 3 krish 19 4 jack 18 6 jill 26 7 nick The index should not be changed and if possible would be nice if I don't have to convert empty strings to NaN. It should be removed only if all the columns have '' empty strings 回答1: You can do: # df.eq('') compare every cell of `df` to `''` # .all(1) or .all(axis=1) checks if all cells on rows are True # ~ is

How to save a list of dataframes to csv

江枫思渺然 提交于 2021-02-20 03:51:46
问题 I have a list of data frames which I reshuffle and then I want to save the output as a csv. To do this I'm trying to append this list to an empty data frame: l1=[year1, year2,..., year30] shuffle (l1) columns=['year', 'day', 'tmin', 'tmax', 'pcp'] index=np.arange(10957) df2=pd.DataFrame(columns=columns, index=index) l1.append(df2) This result in an empty data frames with a bunch of Nans. I don't necessarily need to append my reshuffled list to a dataframe, I just need to save it as a csv, and

R pivot_longer combining columns based on the end of column names

时间秒杀一切 提交于 2021-02-20 02:44:39
问题 I have a dataframe with multiple columns with names of various lengths and structures (so not sure how to capture them with a regex). Each column ends either with .t1 or .t3 I want to combine columns based on names without the t1/t3, with an additional column of Time based on that suffix. So, for example, a dataframe such as: df<-data.frame("Subject"= c(1:10), "intercept.freq.acc.t1" = c(1:10), "intercept.freq.acc.t3" = c(1:10), "freq.rt.t1" = c(1:10), "freq.rt.t3" = c(1:10), "vowel.con.acc

R pivot_longer combining columns based on the end of column names

房东的猫 提交于 2021-02-20 02:43:26
问题 I have a dataframe with multiple columns with names of various lengths and structures (so not sure how to capture them with a regex). Each column ends either with .t1 or .t3 I want to combine columns based on names without the t1/t3, with an additional column of Time based on that suffix. So, for example, a dataframe such as: df<-data.frame("Subject"= c(1:10), "intercept.freq.acc.t1" = c(1:10), "intercept.freq.acc.t3" = c(1:10), "freq.rt.t1" = c(1:10), "freq.rt.t3" = c(1:10), "vowel.con.acc

rbind data.frames in a list in R

风格不统一 提交于 2021-02-19 09:30:30
问题 Suppose we have 3 list s of data.frame s. In BASE R, I was wondering how I could automatically (ex. in a looping structure) rbind the data.frame s within these 3 lists? Please note I want the looping structure so it can rbind any more number of similar lists (ex. g4 g5 ...) g1 <- list(b1 = list(data.frame(a = 1:3, b = 3:5))) g2 <- list(b1 = list(data.frame(a = 1:3, b = 3:5))) g3 <- list(b1 = list(data.frame(a = 1:3, b = 3:5))) 回答1: Here is an option with base R do.call(rbind, lapply(mget(ls

rbind data.frames in a list in R

孤人 提交于 2021-02-19 09:25:12
问题 Suppose we have 3 list s of data.frame s. In BASE R, I was wondering how I could automatically (ex. in a looping structure) rbind the data.frame s within these 3 lists? Please note I want the looping structure so it can rbind any more number of similar lists (ex. g4 g5 ...) g1 <- list(b1 = list(data.frame(a = 1:3, b = 3:5))) g2 <- list(b1 = list(data.frame(a = 1:3, b = 3:5))) g3 <- list(b1 = list(data.frame(a = 1:3, b = 3:5))) 回答1: Here is an option with base R do.call(rbind, lapply(mget(ls

Using dplyr to create new dataframe depending on thresholds

两盒软妹~` 提交于 2021-02-19 08:57:20
问题 Groups Names COL1 COL2 COL3 COL4 1 G1 SP1 1 0.400 0.500 Sequence1 2 G1 SP1 1 0.004 0.005 Sequence2 3 G1 SP1 0 0.004 0.005 Sequence3 4 G1 SP2 0 0.400 0.005 Sequence123 5 G1 SP2 0 0.004 0.500 Sequence14 6 G1 SP3 0 0.005 0.006 Sequence15 7 G1 SP5 1 0.400 0.006 Sequence16 8 G1 SP6 1 0.008 0.002 Sequence20 10 G2 Sp1 0 0.004 0.005 Sequence17 11 G2 SP1 0 0.050 0.600 Sequence18 12 G2 SP1 0 0.400 0.600 Sequence3 13 G2 SP2 0 0.004 0.005 Sequence22 14 G2 SP2 0 0.004 0.005 Sequence23 15 G2 SP5 0 0.004 0