pandas


Pandas Merge duplicate index into single index


I have a simple data frame like this:
d1={'a':{'1998-01-01':10}}
d2={'b':{'1998-01-01':3}}
df=pd.DataFrame.from_dict(d1)
df=df.append(pd.DataFrame.from_dict(d2))
df.index=pd.to_datetime(df.index)
a b
1998-01-01 10 NaN
1998-01-01 NaN 3
I would like to have
a b
1998-01-01 10 3
Since 1998-01-01 share the index

Or you can use groupby by index different way - with parameter level=0 with sum:
print df.groupby(level=0).sum()
a b
1998-01-01 10 3

Alternatively you can try this (with your original data frame):
print(df)
print(df.groupby(df.index).sum())
Output:
a b
1998-01-01 10 NaN
1998-01-01 NaN 3
a b
1998-01-01 10 3


Related Links

MultiIndex and read_table with separate indexes and data
Drop rows of pandas dataframe that don't have finite values in certain variable(s)
concatenate dataframes with different levels of index in pandas
pandas.io.data get_data_yahoo ^DJI retrieval error
“TypeError: only length-1 arrays can be converted to Python scalars”
Pandas resampling hourly timeseries into hourly proportion timeseries
How to customize headers and column widths of DataFrame display?
horizontally centered xlabels for pandas timeseries plotting
drop a single tuple from a multi tuple column
Accessing Row from Previous Day in Pandas Dataframe with Apply
Select a multiple-key cross section from a DataFrame
“Reindexing only valid with uniquely valued Index objects”
How can I divide single values of a dataframe by monthly averages?
How to generate pandas DataFrame column of Categorical from string column?
How to perform key-restricted broadcast-operate-update in Pandas?
partial update to dataframe with Multi-index index with integer labels

Categories

HOME
debugging
view
hashmap
platform-builder
jira
elm
paw-app
packages
flyway4
datastax-java-driver
podio
multiple-records
add
wheelnav.js
handsontable
mapserver
google-cloud-ml
n-gram
fortumo
decimal
try-catch
reactcsstransitiongroup
google-pagespeed
swingx
opencover
excel-2007
pass-by-reference
jndi
h2db
shopware
kannel
user-interaction
wtx
atlassian-crucible
windowbuilder
google-rich-snippets
ecto
copying
gammu
ansible-playbook
angularjs-factory
graphenedb
gzipstream
jvm-languages
netcdf4
businessworks
apple-news
outlook-2013
hibernate-tools
zip4j
pnotify
knockout-components
magma
crypt
np-complete
sybase-asa
specrun
angular-strap
radtreelist
slicknav
fody
trash
xml-attribute
clang-static-analyzer
disque
kendonumerictextbox
coveralls
ideamart
ios9.1
unity3d-gui
mmc
graph-api-explorer
cctv
rdtsc
internet-connection
neolane
castle
elliptic-curve
jquery-layout
comexception
marmalade
ember-charts
gwt-rpc
html4
eventual-consistency
enterprisedb
libstdc++
javaspaces
ocx
reddot
removeclass
libc++
rfc1123
oncheckedchanged
imac
lang
remember-me
lpeg
blitz++
xsdobjectgen
dbal
multi-tier
document-conversion





Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization