I am making a panda dataframe from the weather underground download historical weather data.
Because I do not need all the data, I only use the list of observations. There are two elements in this list - the date and the UTCDT - which are actually dictionaries.
df = pd.DataFrame.from_dict (wu_data ["history"] ["comments"])
I have the 'beautiful' key inside the dictionary I want to index the dataframe created with the parsed date. I can access this value using the array index, but I can not understand how it can directly do without a loop. For example, for the 23rd element I print pretty_date time = parse (pretty_date) print time
pretty_date = df ["date"] values [23] ["beautiful"] > and get me
11:56 PM PDT 05 Apr 2006 2006-04-05 23:56:00
This is what I am doing
g = lambda x: pars (x ["beautiful"]) df_dates = pd.DataFrame.from_dict (df ["date"]) Df Index = df_date ["date"]. Applicable (g)
DF has been redone now. At this point I can remove the columns I do not need.
Is there a more direct way to do this?
Please note that sometimes there are many comments for the same date, but I work with data cleaning, duplicate, etc. in a different part of the code.
Since beautiful
organized dtype only objects You can only take them to a list and get indexed. Not sure that this is what you want:
#include, `r.json` without ()` wu_data = r.json df = pd.DataFrame.from_dict (wu_data [" # Df.index = [purse (df ["date"] [n] "#" ["comments"]) # Using an understanding of the index list, "beautiful" to get the DF ["date"] in the object. ["Beautiful"]) in the range n (len (df))] df.index & class; Class 'pandas.tseries.index.DatetimeIndex' & gt; [2006-04-05 00:56:00, ..., 2006-04-05 23:56:00] Length: 24, Freak: None, Timezone: None
Hope it helps.
Comments
Post a Comment