pandas

Pandas error: Writing as Excel with a MultiIndex is not yet implemented

守給你的承諾、 提交于 2021-02-08 06:40:55
问题 I have a pandas data frame that I create as follows: stats_matrix= #A list containing my data myindex=['','event 1','event 2','event 3','event 4','event 5','event 6','event 7','event 8','event 9','event 10'] #List used for indexing rows column_names=['Failed 1st Stage','% Failed 1st Stage','Active 1st Stage','% Active 1st Stage','Failed 2nd Stage','% Failed 2nd Stage','Failed 1st & 2nd','% Failed 1st & 2nd','Active 2nd Stage','% Active 2nd Stage','Total failed','% Total failed ','Total active

Showing different size circles in heatmap with legend using Matplotlib

我的梦境 提交于 2021-02-08 06:39:39
问题 I am asking a question stemming from this original post Heatmap with circles indicating size of population I am trying to replicate this using my dataframe, however, my circles are non aligning to the plot. Secondary, I want to also create a legend which indicates the value relative to the size of circle. x= {'ID': {0: 'GO:0002474', 1: 'GO:0052548', 2: 'GO:0002483', 3: 'GO:0043062', 4: 'GO:0060333'}, 'TERM': {0: 'antigen processing and presentation of peptide antigen via MHC class I', 1:

Counting qualitative values based on the date range in Pandas

夙愿已清 提交于 2021-02-08 06:33:14
问题 I am learning to use Pandas library and need to perform analysis and plot the crime data set below. Each row represents one occurrence of crime. date_rep column contains daily dates for a year. Data needs to be grouped by month and instances of specific crime need to be added up per month, like in the table below. The problem I am running into is that data in crime column is qualitative and I just cant find resources online that can help me solve this! I have been reading up on groupby and

Replace values in a pandas column using another pandas df which has the corresponding replacements

人盡茶涼 提交于 2021-02-08 06:32:12
问题 I have a pandas df named inventory , which has a column containing Part Numbers (AlphaNumeric). Some of those part numbers have been superseded and I have another df named replace_with containing two columns, 'old part numbers' and 'new part numbers' . For example: Inventory has values like: * 123AAA * 123BBB * 123CCC ...... and replace-with has values like **oldPartnumbers** ..... **newPartnumbers** * 123AAA ............ 123ABC * 123CCC ........... 123DEF SO, i need to replace corresponding

Summing columns in Dataframe that have matching column headers

試著忘記壹切 提交于 2021-02-08 06:22:08
问题 I have a dataframe that currently looks somewhat like this. import pandas as pd In [161]: pd.DataFrame(np.c_[s,t],columns = ["M1","M2","M1","M2"]) Out[161]: M1 M2 M1 M2 6/7 1 2 3 5 6/8 2 4 7 8 6/9 3 6 9 9 6/10 4 8 8 10 6/11 5 10 20 40 Except, instead of just four columns, there are approximately 1000 columns, from M1 till ~M340 (there are multiple columns with the same headers). I wanted to sum the values associated with matching columns based on their index. Ideally, the result dataframe

Pandas Dataframe: Fill Missing Months

匆匆过客 提交于 2021-02-08 05:33:42
问题 I've seen this done with the Panda Timeseries, but was hoping to get some help with Dataframes. I have a file of monthly values from 1966-2009. I do not have data for the year 1985 and would like to add data for 2010/2011 as well. These additions would simply have NaNs attached to them. With the code below, I'm trying to cut my dataset so that it starts at 1980 and then add in the years that are missing with NaN values attached. However, nothing gets cut and nothing is added. Is there

reading millisecond data into pandas

荒凉一梦 提交于 2021-02-08 05:31:29
问题 I have a file with data like this, and want to load it, and use timestamp column (which denotes milliseconds) as a DateTimeIndex. x y timestamp 0 50 90 125 37 87 234 37 87 344 37 87 453 37 87 562 26 78 656 26 78 766 26 78 875 26 78 984 30 77 when I specify timestamp as index, it becomes FloatIndex cur_df = pd.read_csv(cur_file, sep=',', comment='#', index_col = 'timestamp', parse_dates=True) EDIT: I added a function to parse dates, adding a dummy date: def convert_time(a): sec = int(math

reading millisecond data into pandas

狂风中的少年 提交于 2021-02-08 05:30:07
问题 I have a file with data like this, and want to load it, and use timestamp column (which denotes milliseconds) as a DateTimeIndex. x y timestamp 0 50 90 125 37 87 234 37 87 344 37 87 453 37 87 562 26 78 656 26 78 766 26 78 875 26 78 984 30 77 when I specify timestamp as index, it becomes FloatIndex cur_df = pd.read_csv(cur_file, sep=',', comment='#', index_col = 'timestamp', parse_dates=True) EDIT: I added a function to parse dates, adding a dummy date: def convert_time(a): sec = int(math

pandas add columns ,note The truth value of a Series is ambiguous

只愿长相守 提交于 2021-02-08 05:18:24
问题 I want do add a column to dataframe a, a = pd.DataFrame([[1,2],[3,4]],columns=['A','B']) if a['B'] > a['A']: a['C']='是' else: a['C']='否' ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). 回答1: Use numpy.where: #swapped 2,1 a = pd.DataFrame([[2,1],[3,4]],columns=['A','B']) a['C'] = np.where(a['B']>a['A'], '是','否') print (a) A B C 0 2 1 否 1 3 4 是 Problem with your code is if use: print (a['B']>a['A']) 0 False 1 True dtype: bool it return

pandas add columns ,note The truth value of a Series is ambiguous

本小妞迷上赌 提交于 2021-02-08 05:17:34
问题 I want do add a column to dataframe a, a = pd.DataFrame([[1,2],[3,4]],columns=['A','B']) if a['B'] > a['A']: a['C']='是' else: a['C']='否' ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). 回答1: Use numpy.where: #swapped 2,1 a = pd.DataFrame([[2,1],[3,4]],columns=['A','B']) a['C'] = np.where(a['B']>a['A'], '是','否') print (a) A B C 0 2 1 否 1 3 4 是 Problem with your code is if use: print (a['B']>a['A']) 0 False 1 True dtype: bool it return