Convert list of dictionaries to a pandas DataFrame

I have a list of dictionaries like this: [{‘points’: 50, ‘time’: ‘5:00’, ‘year’: 2010}, {‘points’: 25, ‘time’: ‘6:00’, ‘month’: “february”}, {‘points’:90, ‘time’: ‘9:00’, ‘month’: ‘january’}, {‘points_h1’:20, ‘month’: ‘june’}] And I want to turn this into a pandas DataFrame like this: month points points_h1 time year 0 NaN 50 NaN 5:00 2010 1 february 25 NaN … Read more

How to deal with SettingWithCopyWarning in Pandas

Background I just upgraded my Pandas from 0.11 to 0.13.0rc1. Now, the application is popping out many new warnings. One of them like this: E:\FinReporter\FM_EXT.py:449: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_index,col_indexer] = value instead quote_df[‘TVol’] = quote_df[‘TVol’]/TVOL_SCALE I want to know … Read more

How to drop rows of Pandas DataFrame whose value in a certain column is NaN

I have this DataFrame and want only the records whose EPS column is not NaN: >>> df STK_ID EPS cash STK_ID RPT_Date 601166 20111231 601166 NaN NaN 600036 20111231 600036 NaN 12 600016 20111231 600016 4.3 NaN 601009 20111231 601009 NaN NaN 601939 20111231 601939 2.5 NaN 000001 20111231 000001 NaN NaN …i.e. something like … Read more

How to add a new column to an existing DataFrame?

I have the following indexed DataFrame with named columns and rows not- continuous numbers: a b c d 2 0.671399 0.101208 -0.181532 0.241273 3 0.446172 -0.243316 0.051767 1.577318 5 0.614758 0.075793 -0.451460 -0.012493 I would like to add a new column, ‘e’, to the existing data frame and do not want to change anything in … Read more

Create a Pandas Dataframe by appending one row at a time

How do I create an empty DataFrame, then add rows, one by one? I created an empty DataFrame: df = pd.DataFrame(columns=(‘lib’, ‘qty1’, ‘qty2’)) Then I can add a new row at the end and fill a single field with: df = df._set_value(index=len(df), col=”qty1″, value=10.0) It works for only one field at a time. What is … Read more

Change column type in pandas

I want to convert a table, represented as a list of lists, into a pandas DataFrame. As an extremely simplified example: a = [[‘a’, ‘1.2’, ‘4.2’], [‘b’, ’70’, ‘0.03’], [‘x’, ‘5’, ‘0’]] df = pd.DataFrame(a) What is the best way to convert the columns to the appropriate types, in this case columns 2 and 3 … Read more