Rename Pandas DataFrame Index

I’ve a csv file without header, with a DateTime index. I want to rename the index and column name, but with df.rename() only the column name is renamed. Bug? I’m on version 0.12.0 In [2]: df = pd.read_csv(r’D:\Data\DataTimeSeries_csv//seriesSM.csv’, header=None, parse_dates=[[0]], index_col=[0] ) In [3]: df.head() Out[3]: 1 0 2002-06-18 0.112000 2002-06-22 0.190333 2002-06-26 0.134000 2002-06-30 … Read more

Compare two DataFrames and output their differences side-by-side

I am trying to highlight exactly what changed between two dataframes. Suppose I have two Python Pandas dataframes: “StudentRoster Jan-1”: id Name score isEnrolled Comment 111 Jack 2.17 True He was late to class 112 Nick 1.11 False Graduated 113 Zoe 4.12 True “StudentRoster Jan-2”: id Name score isEnrolled Comment 111 Jack 2.17 True He … Read more

Pandas dataframe fillna() only some columns in place

I am trying to fill none values in a Pandas dataframe with 0’s for only some subset of columns. When I do: import pandas as pd df = pd.DataFrame(data={‘a’:[1,2,3,None],’b’:[4,5,None,6],’c’:[None,None,7,8]}) print df df.fillna(value=0, inplace=True) print df The output: a b c 0 1.0 4.0 NaN 1 2.0 5.0 NaN 2 3.0 NaN 7.0 3 NaN 6.0 … Read more

How to split data into 3 sets (train, validation and test)?

I have a pandas dataframe and I wish to divide it to 3 separate sets. I know that using train_test_split from sklearn.cross_validation, one can divide the data in two sets (train and test). However, I couldn’t find any solution about splitting the data into three sets. Preferably, I’d like to have the indices of the … Read more