pandas

Dataframe divide series on pandas

本小妞迷上赌 提交于 2021-02-10 02:40:43
问题 I need to divide each column of the matrix df1 into a single column of the matrix df2 . To get a matrix with dimension df1 (3*2). I need a result: dataframe[[1/6, 2/7, 3/8], [3/6, 4/7, 5,8]] df1 = pd.DataFrame(data = [[1,2,3],[3,4,5]], index = ['a','b'], columns = ['i','ii','iii']) df2 = pd.DataFrame(data = [[6],[7],[8]], index = ['a','b','c'], columns = ['i']) df1.div(df2, axis = 'columns') => does not work for i in range(0,2) a = df1[df1.columns[i]] / df2 => summarizes the result in one

Dataframe divide series on pandas

*爱你&永不变心* 提交于 2021-02-10 02:31:26
问题 I need to divide each column of the matrix df1 into a single column of the matrix df2 . To get a matrix with dimension df1 (3*2). I need a result: dataframe[[1/6, 2/7, 3/8], [3/6, 4/7, 5,8]] df1 = pd.DataFrame(data = [[1,2,3],[3,4,5]], index = ['a','b'], columns = ['i','ii','iii']) df2 = pd.DataFrame(data = [[6],[7],[8]], index = ['a','b','c'], columns = ['i']) df1.div(df2, axis = 'columns') => does not work for i in range(0,2) a = df1[df1.columns[i]] / df2 => summarizes the result in one

Resolving Reindexing only valid with uniquely valued Index objects

我的未来我决定 提交于 2021-02-09 15:17:10
问题 I have viewed many of the questions that come up with this error. I am running pandas '0.10.1' df = DataFrame({'A' : np.random.randn(5), 'B' : np.random.randn(5),'C' : np.random.randn(5), 'D':['a','b','c','d','e'] }) #gives error df.take([2,0,1,2,3], axis=1).drop(['C'],axis=1) #works fine df.take([2,0,1,2,1], axis=1).drop(['C'],axis=1) Only thing I can see is that in the former case I have the non-numeric column, which seems to be affecting the index somehow but the below command returns

Resolving Reindexing only valid with uniquely valued Index objects

只谈情不闲聊 提交于 2021-02-09 15:14:20
问题 I have viewed many of the questions that come up with this error. I am running pandas '0.10.1' df = DataFrame({'A' : np.random.randn(5), 'B' : np.random.randn(5),'C' : np.random.randn(5), 'D':['a','b','c','d','e'] }) #gives error df.take([2,0,1,2,3], axis=1).drop(['C'],axis=1) #works fine df.take([2,0,1,2,1], axis=1).drop(['C'],axis=1) Only thing I can see is that in the former case I have the non-numeric column, which seems to be affecting the index somehow but the below command returns

Resolving Reindexing only valid with uniquely valued Index objects

大憨熊 提交于 2021-02-09 15:14:03
问题 I have viewed many of the questions that come up with this error. I am running pandas '0.10.1' df = DataFrame({'A' : np.random.randn(5), 'B' : np.random.randn(5),'C' : np.random.randn(5), 'D':['a','b','c','d','e'] }) #gives error df.take([2,0,1,2,3], axis=1).drop(['C'],axis=1) #works fine df.take([2,0,1,2,1], axis=1).drop(['C'],axis=1) Only thing I can see is that in the former case I have the non-numeric column, which seems to be affecting the index somehow but the below command returns

Displaying Pandas dataframe in tkinter

自古美人都是妖i 提交于 2021-02-09 11:50:33
问题 I'm creating a tkinter gui that will take user input for a variable that then gets passed to SQL and the queried data (in this case a single column data frame and boxplot). However, at this moment I can not find a means of displaying my pandas dataframe in the tk gui. I have not found any module or means of displaying this, and I've spent hours going through possible solutions to no avail. Only thing I need is for the dataframe to display in the gui and be re-rendered each time I change the

Why can't I subtract one date period from the next and convert to an integer?

风格不统一 提交于 2021-02-09 11:12:24
问题 I am trying to determine whether a difference between two months is an even or odd number of months. I used the command: import pandas as pd (pd.to_datetime('2019-01-01').to_period('M') - pd.to_datetime('2018-08-01').to_period('M')) % 2 This seems to work in python 3.6.7, but in another python 3.7.3 environment I get the error: >>> import pandas as pd >>> (pd.to_datetime('2019-01-01').to_period('M') - pd.to_datetime('2018-08-01').to_period('M')) % 2 Traceback (most recent call last): File "

Why can't I subtract one date period from the next and convert to an integer?

与世无争的帅哥 提交于 2021-02-09 11:10:44
问题 I am trying to determine whether a difference between two months is an even or odd number of months. I used the command: import pandas as pd (pd.to_datetime('2019-01-01').to_period('M') - pd.to_datetime('2018-08-01').to_period('M')) % 2 This seems to work in python 3.6.7, but in another python 3.7.3 environment I get the error: >>> import pandas as pd >>> (pd.to_datetime('2019-01-01').to_period('M') - pd.to_datetime('2018-08-01').to_period('M')) % 2 Traceback (most recent call last): File "

Pandas: Divide column data by number if row of next column contains certain value

雨燕双飞 提交于 2021-02-09 11:10:03
问题 I have a dataframe that consists of three columns qty unit_of_measure qty_cal 3 nodes nan 4 nodes nan 5 nodes nan 6 cores nan 7 nodes nan 10 cores nan 3 nodes nan I would like to add a condition to populate qty_cal . The condition is if unit_of_measure is equal to "nodes" populate the row value of qty into qty_cal If it's "cores" divide qty value by 16 and populate qty_cal The code I have tried is, if ppn_df['unit_of_measure'] == 'Nodes': ppn_df['qty'] elif ppn_df['unit_of_measure'] =='Cores'

Pandas: Divide column data by number if row of next column contains certain value

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-09 11:08:05
问题 I have a dataframe that consists of three columns qty unit_of_measure qty_cal 3 nodes nan 4 nodes nan 5 nodes nan 6 cores nan 7 nodes nan 10 cores nan 3 nodes nan I would like to add a condition to populate qty_cal . The condition is if unit_of_measure is equal to "nodes" populate the row value of qty into qty_cal If it's "cores" divide qty value by 16 and populate qty_cal The code I have tried is, if ppn_df['unit_of_measure'] == 'Nodes': ppn_df['qty'] elif ppn_df['unit_of_measure'] =='Cores'