I am new to Python and Pandas. I wrote a little code to download 1 minute data from Google Finance. After using the following command:
new = pd.read_csv(string, skiprows=7, names = ("d", "o", "h", "l", "c", "v") )
I obtain a DataFrame such as the following:
d o h l c v 0 a1453905960 95.4500 95.4500 95.0900 95.0980 433810 1 a1453906020 95.0500 95.4700 94.9500 95.4500 934980 2 a1453906080 94.9400 95.1000 94.8700 95.0900 791657 3 a1453906140 94.8990 95.0300 94.7000 94.9620 763531 4 a1453906200 94.9300 95.0300 94.8200 94.8918 501298
where the first column is unix timestamp.
Next, I convert the unix timestamp into regular datetime with the following line
new['d']=new['d'].apply(lambda x:datetime.fromtimestamp(int(x[1:])).strftime('%Y-%m-%d %H:%M:%S'))
Now my d column contains strings with dates. If I use the following lines
new.index = new["d"]
del new["d"]
I just replace the old index with a new index made of strings containing datetimes. If I plot the c column with the following command
new["c"].plot()
If instead I convert the index of my dataframe to datetime object with the following command
new.index = pd.to_datetime(new.index)
and then I try
new["c"].plot()
Why? What am I misunderstanding?
Thank you in advance.