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

Pandas Resample Strange Zero Tolerance Behavior
VLOOKUP equivalent function to look up value in pandas DataFrame
pandas dataframe shift dates
ipython dataframe plotting setting color parameter?
How to change string columns size for all columns in pandas hdfstore?
is there an equivalent of data-frame in OCaml?
Pandas option to keep levels after xs operation
Pandas DataFrame Column rename error… am I'm being silly?
Assigning one column to another column between pandas DataFrames (like vector to vector assignment)
Incompatible indexer with Series
data wrangling with Flask: how to do this using SQL language? Does it make sense to use pandas?
Update columns in dataframe inside panel without for loop?
get grouping level in agg function
getting a default value from pandas dataframe when a key is not present
Convert Pandas dataframe to time series
Pandas dataframe values equality test

Categories

HOME
xamarin
youtube-dl
tizen-web-app
sharepoint-designer
c#-2.0
gps
installshield
ojdbc
pivotal-cloud-foundry
flyway4
networkx
virtualization
qt-creator
google-cloud-spanner
event-handling
iolanguage
ghc
graphlab
openrefine
highlight.js
saxon
invantive-sql
undefined
beyondcompare
predix
xlsxwriter
emgucv
tdd
atlassian-crucible
skia
lightswitch-2013
media-queries
galsim
textmate
y86
force-layout
revolution-slider
io-redirection
swisscomdev
starteam
squib
ruby-on-rails-3.1
gulp-sourcemaps
isbn
convertapi
galleria
angular-resource
jedis
svmlight
lowpass-filter
dtexec
pillow
titanium-android
mediaelement
fputcsv
blackberry-10
pickadate
phpcas
vhd
wso2cloud
t4mvc
thredds
jmeter-maven-plugin
quicklisp
map-projections
splash
ios9.1
p2
lustre
block-device
camanjs
gui-test-framework
html-helper
terminfo
xojo
article
aapt
uitouch
rebol3
yorick
prettify
terminal-services
apc
drools-planner
pvrtc
path-separator
trusted
datawindow
labwindows
objective-c-2.0
gnustep
stage
coredump
disclosure
oncheckedchanged
database-management
audio-capture
libs
microsoft-virtualization
javap
thread-local-storage
gacutil

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