1
文字列による値をタイムチャートにプロットする方法を見つけることができません。日付によるプロット値は文字列で示されます
ここは私のデータです。
(CSVからの)入力:
Fecha,Pais,count
"20/05/2017",Brazil,1
"20/05/2017",China,821
"20/05/2017",Czechia,31
"20/05/2017",France,1
"20/05/2017","Republic of Korea",1
"21/05/2017",Argentina,5
"21/05/2017",Australia,2
"21/05/2017",China,3043
"21/05/2017",Denmark,1
"21/05/2017",Egypt,1
...
..
.
I日付、文字列とよく解析された整数値を持つCSVデータらをインポートした:実際に
DatetimeIndex(['2017-05-20', '2017-05-20', '2017-05-20', '2017-05-20',
'2017-05-20', '2017-05-21', '2017-05-21', '2017-05-21',
'2017-05-21', '2017-05-21', '2017-05-21', '2017-05-21',
'2017-05-21', '2017-05-21', '2017-05-21', '2017-05-21',
'2017-05-21', '2017-05-21', '2017-05-21', '2017-05-21',
'2017-05-22', '2017-05-22', '2017-05-22', '2017-05-22',
'2017-05-22', '2017-05-22', '2017-05-22', '2017-05-22',
'2017-05-22', '2017-05-22', '2017-05-22', '2017-05-22',
'2017-05-22', '2017-05-22', '2017-05-22', '2017-05-22'],
dtype='datetime64[ns]', freq=None)
['Brazil' 'China' 'Czechia' 'France' 'Republic of Korea' 'Argentina'
'Australia' 'China' 'Denmark' 'Egypt' 'France' 'Hungary' 'Netherlands'
'Oman' 'Republic of Korea' 'Russia' 'Slovak Republic' 'Taiwan' 'Ukraine'
'United Arab Emirates' 'Argentina' 'Brazil' 'China' 'Czechia' 'Ecuador'
'France' 'Germany' 'India' 'Latvia' 'Liberia' 'Pakistan' 'Peru'
'Republic of Korea' 'Russia' 'Taiwan' 'Ukraine']
['1' '821' '31' '1' '1' '5' '2' '3043' '1' '1' '1' '1' '1' '1' '1' '1' '1'
'3' '48' '1' '2' '1' '3759' '79' '2' '1' '3' '1' '192' '1' '1' '1' '1' '2'
'1' '1']
Iが持っていますプロット:
しかし、私は値を参加can't同じ国では、データが含まれている日付でそれぞれの履歴をプロットします。ここで
は私のコードです:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter, DayLocator, AutoDateLocator, AutoDateFormatter
import datetime
locator = DayLocator()
formatter = AutoDateFormatter(locator)
date, country, count = np.loadtxt("72hcountcountry.csv",
delimiter=',',
unpack=True,
dtype='string',
skiprows=1)
date = np.char.replace (date, '"', '')
country = np.char.replace (country, '"', '')
date2 = pd.to_datetime(date, format="%d/%m/%Y")
print date2
print country
print count
fig, ax = plt.subplots()
ax.plot_date(date2, count)
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(formatter)
ax.autoscale_view()
ax.grid(True)
fig.autofmt_xdate()
plt.show()
はどうすれば各国がデータに合わせて、それぞれの日付をプロット分けることができますか?
また、最後にあなたの実際の質問に関連する質問のタイトルをもう1つ変更することをお勧めしますか? 「列の1つに(文字列)値で区切られたファイルからのプロットデータ」と同様のものが、IMHOのほうが良いかもしれません。 –
ありがとうございます@Pablo –