2017-09-05 40 views
3

我的數據框中有兩列。日期格式中的一列。另一列有1和0。我想繪製出兩個columns.Here之間關係的圖表是我的數據使用matplotlib或seaborn繪製兩列之間的關係

Date received Consumer disputed? 
15-05-2014 0 
18-09-2014 0 
13-03-2014 0 
17-07-2015 1 
20-11-2014 0 
26-06-2014 0 
28-09-2012 0 
06-05-2015 1 
25-02-2013 0 
30-03-2016 0 
21-03-2014 0 

的小片段的情節應該是這樣的:1和0的分佈相對於日專門月份部分如此我可以決定哪個月有更多的1,哪些有更多的0。在此先感謝

+0

如果一個月沒有出現,這是否意味着該值是0? –

+0

每個月都不會出現月份。可以說1和0是隨機分佈的..更多1在幾個月內,而在其他一些上更少。使用我需要決定哪一年的哪一部分有更多的消費者爭議(1是肯定的,0是沒有在消費者爭議專欄) – Biswa

回答

0

沿東西線...

import matplotlib.pyplot as plt 
% matplotlib inline 
df['Date'] = pd.to_datetime(df['Date']) 
x = df['Date'].values 
y = df['received'].values 
plt.scatter(x,y) 
plt.show() 
2

我會用條形圖

df['Consumer disputed?'].groupby(df['Date received'].dt.month).sum().plot.bar() 

enter image description here

1

你也許可以使用jointplot從Seaborn

data['month'] = pd.to_datetime(data['Date']).dt.month 
sns.jointplot(x='Consumer',y='month',data=data)] 

enter image description here

+0

它不工作。顯示錯誤「ValueError:第一個參數必須是一個序列」 – Biswa

+0

你可以檢查列的數據類型,並確保它是int64? – Gayatri

0

這裏是我的問題的解決方案。

#extract the month form the date 

train_data['month'] = pd.to_datetime(train_data['Date received']).dt.month 

#crosstab displays the frequency distribution of the variable 
#(here "Consumer disputed?") in a matrix format` 
b = pd.crosstab(train_data['month'], train_data['Consumer disputed?']) 


#transform the label month into a column 
b.reset_index(level='month', inplace=True) 

enter image description here

#plot the graph 
b.plot('month', 'Yes') 

enter image description here