Can't pass pandas Series to pyplot's fill_between function?
Date : March 29 2020, 07:55 AM
this will help Because matplotlib is written to take sequence or np.ndarray-like objects as arguments (and knows nothing about pandas). In the cases where all of the methods used internally work the same on pandas objects and numpy objects, then it works (the magic of duck typing). In cases where pandas objects do not behave correctly (in this case using v[-1] to get the last element of the first dimension out) it will raise errors. If a given function works with the pandas objects depends on the internals of the function and is not guaranteed to be stable even between minor releases of mpl because you are essentially using matplotlib in an undocumented way.
|
KeyError when extracting data from a pandas.core.series.Series
Tag : python , By : user186012
Date : March 29 2020, 07:55 AM
To fix the issue you can do In the following ipython3 session, I read differently-formatted tables and make the sum of the values found in one of the columns: , I think you need: #select first value of one element series
f = F.iat[0]
#alternative
#f = F.iloc[0]
#convert to numpy array and select first value
f = F.values[0]
f = F.item()
f = F[72]
#f = f.loc[72]
s = S[6]
#s = S.loc[6]
F = pd.Series([3164181], index=[72])
f = F[72]
print (f)
3164181
print (F.index)
Int64Index([72], dtype='int64')
print (F.index.tolist())
[72]
f = F[0]
print (f)
|
Reindexing a pandas series with a set of strings is removing the orignial data in the series
Tag : python , By : Marcos de Carvalho
Date : March 29 2020, 07:55 AM
wish helps you I worked around this problem by creating dictionary and zipping a list of weekdays, to the initial series, and then creating a dataframe from the dictionary. hour_counts = _scrobbles['dow'].value_counts().sort_index()
days = 'Mon Tue Wed Thu Fri Sat Sun'.split()
df = pd.DataFrame(list(dict(zip(days, hour_counts)).items()), columns=['Month', 'Count'])
|
Most efficient method for creating new binary Series based on conditional in Pandas when the old series has missing data
Date : March 29 2020, 07:55 AM
wish helps you No, there's not a single pattern because each selection is logically different. Any ==, <, <=, >, or > comparison with at least one NaN evaluates to False. pandas is correct in returning False for NaN < 12 because that's the standard. Deviating from this requires your own logic.
|
How to covert lists of dict time series data to pandas series?
Date : March 29 2020, 07:55 AM
it should still fix some issue You can iterate through the list of dicts, only keeping the stuff that looks like a timestamp, make it a dataframe, and turn it into a series with time as the index. data = [{'00:00:00': 1430801.0,
'00:05:00': 1430806.0,
'00:10:00': 1430811.0,
'00:15:00': 1430815.0,
'00:20:00': 1430821.0,
'dt': '2016-07-18',
'a': 'Jack',
'b': 'Tony'},
{'00:10:00': 1430201.0,
'00:25:00': 1430106.0,
'00:40:00': 1430311.0,
'00:55:00': 1430415.0,
'01:10:00': 1430521.0,
'dt': '2016-07-19',
'a': 'Jack',
'b': 'Tony'}]
import re
pat = re.compile(r'\d{2}:\d{2}:\d{2}')
pd.DataFrame([[r['dt']+' '+k, v] for r in data for k, v in r.items() if pat.match(k)], columns=['tm', 'v']).set_index('tm')['v']
|