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

Mapping to similar times in Pandas
Pandas Unmelt dataset
multicollinearity for one-hot encoding
How to work with 'NA' in pandas?
Pandas DataFrame.assign arguments
zipline error KeyError: <type 'zipline.assets._assets.Equity'>
How can i split 'Date' column into 'Date' and 'Time' column? [closed]
Pandas customized group aggregation
What is the significance of t-stats value while applying ttest_ind on two pandas series?
Align order of multiindex dataframe with the order of another multiindex df, pandas
From Object To Date in Pandas [duplicate]
How do I configure PyCharm to Pandas
cannot convert nan to int (but there are no nans)
2 dimension time series groupby in pandas
display the rows based on the last occurrence of an element in a column in Pandas dataframe
How to clip pandas dataframe in place

Categories

HOME
google-chrome-extension
winforms
cookies
keras
angular-material
json.net
relayjs
cplex
rubygems
cakephp-2.5
retrofit
alpha
cross-browser
in-app-purchase
directx
tomcat6
static-libraries
hapi
lombok
saxon
pugjs
scichart
jquery-ajaxq
mps
graphicsmagick
sylius
accessor
excel-2007
restful-authentication
claims-based-identity
lcd
icloud-api
crystal-reports-2010
kannel
web-api-testing
msys2
large-file-upload
libssl
c++-amp
gsmcomm
instant-messaging
pdb
caret
hybridauth
textmate
android-kernel
http-referer
wpf-controls
withings
hilbert-curve
angularjs-factory
grid.mvc
acoustics
cubic-spline
revapi
aurelia-validation
worker-thread
media-player
account-kit
background-service
pintos
database-optimization
lttng
angstrom-linux
simplewebrtc
ubuntu-10.04
superstack
ready-api
packagist
phpcas
jms2
cartesian-product
truevault
python-green
c3
xc16
cdt
phalanger
id3v2
wordpress-theme-customize
issuu
rdl
ceil
system.net.webexception
algebraic-data-types
srs
terminal-services
uv-mapping
page-layout
dexterity
quartz-graphics
seed
interface-orientation
factory-method
referrer
e4x
errai
jspinclude
regsvr32
enter
pendrive
netdna-api
stage
subgurim-maps
horizontal-accordion
android-sdk-2.1
web-application-design
bespin
multi-tier
audio-capture
iweb
exchange-server-2003
temporal-database
pascal-fc
spec#
windows-live-messenger

Resources

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