2017-04-22 4 views
-2

私はパンダには新しく、ダム散布図では苦労しています。パンダのシンプルなX、Yスキャッタで悩む

私はそれをどのようにして列と時間をプロットして日付を入れたいですか?

data = [('04/22', 9), ('04/22', 5), ('04/22', 7), ('04/22', 20), ('04/21', 14), ('04/21', 9), ('04/21', 7), ('04/21', 12), ('04/21', 9), ('04/21', 5)] 

df = pandas.DataFrame(data,columns=['Date', 'Time']) 

print(df) 
df.groupby('Date') 
df.plot(x='Date', y='Time') 

マイ出力:

enter image description hereあなたは、私は、'04/22' 、'04/21' を置くことを意味... X上で(文字列に対処する方法を決定する必要があり

+0

それでプロットしようとするとどうなりますか? – Peaceful

+0

が更新しました。 – bigo

答えて

0

何に基づいて軸ですか?)。簡単な例と複雑な例を紹介します。

import pandas as pd 
import matplotlib.pyplot as plt 

data = [('04/22', 9), ('04/22', 5), ('04/22', 7), ('04/22', 20), ('04/21', 14), ('04/21', 9), ('04/21', 7), ('04/21', 12), ('04/21', 9), ('04/21', 5)] 

df = pd.DataFrame(data, columns=['Date', 'Time']) 

# I decided just using integer of index. 
df = df.groupby('Date').sum().reset_index().reset_index() 
df.plot.scatter(x='index', y='Time') 

y_lab = [str(e) for e in df['Date']] 
plt.xticks(df.index, y_lab, rotation=0, size=6) 
plt.xlabel('Date') 
plt.show() 

enter image description here

そして、あなたはdatetime型のインデックスを使用したい場合は、私のanother answerを確認してください。そして、私はこれが最終的にあなたにとってもっと役に立つかもしれないと思います。

enter image description here

関連する問題