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

how to perform where and distinct count operation in pandas dataframe?
Pandas Dataframe - Using index as value when slicing/filtering
How can I select out columns where the first values are NaN?
Record limitation in pandas dataframe when importing from a csv file
count of unique values in pandas dataframe column
Rolling sums on pandas dataframe
Pandas Bug - Error when inserting list serialize as string
Formatting index of a pandas table in a plot
resample over consecutive chunks of large size CSV
Too many possibilities for categorical fields
How to install pandas on virtual machine?
How to change particular column value when defined mask is true?
Pandas/NumPy: concisely label first N values matching a mask
fast way to make index prefix with an alphabet
Is there a way to better format Pandas data frames when printing them in Sublime text?
Pandas pivot certain rows to columns

Categories

HOME
yii2
log4j
date
clips
atom-editor
netbeans
keras
server
alfresco
read-eval-print-loop
analysis
amazon-ecs
rubygems
frameworks
umd
cross-browser
swagger-ui
paradox
add
gorm
spring-kafka
apache-cayenne
messages
dtrace
flask-wtforms
circuit
finite-automata
contextmenu
kryo
google-search-api
java-7
kannel
nhapi
web-api-testing
strncpy
typo3-6.2.x
saas
gitignore
subdomains
nat
google-qpx-express-api
grails-3.1
android-kernel
html5-fullscreen
vxworks
hockeyapp
az-application-insights
android-fingerprint-api
elasticsearch-plugin
greenrobot-eventbus
fedex
ncalc
quadratic-programming
google-closure
firebase-admin
fakeiteasy
http-redirect
logfiles
user-accounts
parentheses
mu
tactic
libusb-win32
titanium-android
objective-c-swift-bridge
time-and-attendance
wdf
ctest
hill-climbing
ready-api
qgraphicsview
make-install
bluegiga
rhino-servicebus
jfugue
javax.sound.midi
xna-4.0
spidermonkey
kcachegrind
ideamart
php-ci
mono-embedding
composite
sonarqube5.1.2
facebook-graph-api-v2.4
c3
cctv
wordpress-theme-customize
tld
jboss-weld
hyprlinkr
cloud-connect
ccss
dir
django-nonrel
drools-planner
ocunit
delphi-6
simba
sublist
runas
venn-diagram
onsubmit
postgresql-performance
spring-portlet-mvc
subscript
netbeans-7.1
android-sdk-2.1
mongomapper
createwindow
.nettiers
thread-local-storage
spec#
windows-live-messenger
paul-graham
misv

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
Mobile App
Mobile App
Mobile App