series

Why does .loc work with integer index positions?

风格不统一 提交于 2019-12-11 19:12:59
问题 The pandas documentation of .loc clearly states: .loc is strictly label based, will raise KeyError when the items are not found, allowed inputs are: A single label, e.g. 5 or 'a', (note that 5 is interpreted as a label of the index. This use is not an integer position along the index) Contrary to that, this surprisingly works for pd.Series , not for pd.DataFrame: import numpy as np a = np.array([1,3,1,2]) import pandas as pd s = pd.Series(a, index=["a", "b", "c", "d"]) s.loc["a"] # yields 1 s

Computing a series with large numbers : Python

*爱你&永不变心* 提交于 2019-12-11 17:42:24
问题 Note: Corrected the silly mistake pointed out in the line for i in xrange(10000) I am writing a code for calculating and plotting MittagLeffler functions using a series expansion, import numpy as np import scipy as sp from decimal import Decimal import pylab as plt from math import gamma def MLf(x,a): mlf = Decimal(0) X = (x) term = Decimal(0) for j in xrange(100): term = Decimal((-1)**j*(X**(j*a)))/Decimal(gamma(a*j+1)) mlf = Decimal( term + mlf ) return mlf x = np.arange(0,1000,0.1) y = np

pandas: return all matched keys for each strings value in a series

我怕爱的太早我们不能终老 提交于 2019-12-11 14:18:51
问题 How to return all the matched keys of from a search list as comma-separated values. For example, s = pd.Series(['cat dog','hat cat','dog','fog cat','pet']) searchfor = ['cat', 'dog'] I want to get this: ['cat, dog', 'cat', 'dog', 'cat', 'None'] 回答1: Just split it 1st then doing str.contains s1=s.str.split(' ',expand=True).stack() s1[s1.str.contains('|'.join(searchfor))].groupby(level=0).apply(' '.join).reindex(s.index) Out[778]: 0 cat dog 1 cat 2 dog 3 cat 4 NaN dtype: object 回答2: My

JFreeChart XYSeries as Strings

依然范特西╮ 提交于 2019-12-11 13:18:45
问题 im working with jfreechart and try to make a XYLineChart which is working very well. My problem is, that the y label are double values and i need strings. My Code: DefaultXYDataset result = new DefaultXYDataset(); XYSeries series1 = new XYSeries("Words"); series1.add(0, 0.3); series1.add(1, 0.5); series1.add(2, 0.6); series1.add(3, 0.3); series1.add(4, 0.2); series1.add(5, 1); result.addSeries(getTitle(), series1.toArray()); I want something like: XYSeries series1 = new XYSeries("Words");

how to extract pandas series element and compare it with rows in dataframe's column

时光怂恿深爱的人放手 提交于 2019-12-11 12:43:07
问题 I have a following dataframe.. coupon_type dish_id dish_name dish_price dish_quantity 0 Rs 20 off 012 Sandwich 65 2 1 Rs 20 off 013 Chicken 125 3 2 Rs 20 off 013 Chicken 125 3 3 Rs 20 off 013 Chicken 125 3 ratings reviews coupon_type user_id order_id meals order_area 4 blah blah blah Rs 20 off 9 9 5 London 4 blah blah blah Rs 20 off 9 9 5 London 3 blah blah blah Rs 20 off 9 9 5 London 4 blah blah blah Rs 20 off 9 9 5 London I am doing groupby on dish_name column. df_dish_name = df_final

Pandas.Series.dtype.kind is None for pd.interval

余生长醉 提交于 2019-12-11 12:39:39
问题 Test code: s = pd.Series(pd.array([pd.Interval(0,1.2), pd.Interval(5,123)])) s.dtype s.dtype.kind is None >>> interval[float64] >>> True Is it some bug or made intentionally? If latter - for what reason? 回答1: The reason this is appearing as None is simply because the implementation of IntervalDtype explicitly sets kind = None. This should probably be updated to 'O' , though some care is needed here as it will result in unintended side effects, e.g. this would cause is_string_dtype to return

Why do Chart Stacked Columns show up as thin lines?

眉间皱痕 提交于 2019-12-11 10:53:51
问题 I am trying to create a stacked column chart with 4 series in it. But somehow, after populating the series and making sure they are aligned, instead of columns, thin lines appears. Code is as below. foreach (Series s in chartEvents.Series) s.Points.Clear(); foreach (DataRow dr in data.Rows) { string reason = ""; double xVal = 0; double yVal = 0; double overFlow = 0; double existFlow = 0; try { reason = dr["reasonID"].ToString(); xVal = Math.Round(Convert.ToDateTime(dr["XValue"].ToString())

Expand pandas dataframe column of dict into dataframe columns [duplicate]

时间秒杀一切 提交于 2019-12-11 08:57:33
问题 This question already has answers here : Python/pandas: data frame from series of dict: optimization (2 answers) Closed 11 months ago . I have a Pandas DataFrame where one column is a Series of dicts, like this: colA colB colC 0 7 7 {'foo': 185, 'bar': 182, 'baz': 148} 1 2 8 {'foo': 117, 'bar': 103, 'baz': 155} 2 5 10 {'foo': 165, 'bar': 184, 'baz': 170} 3 3 2 {'foo': 121, 'bar': 151, 'baz': 187} 4 5 5 {'foo': 137, 'bar': 199, 'baz': 108} I want the foo , bar and baz key-value pairs from the

Python Pandas : pandas.to_datetime() is switching day & month when day is less than 13

孤街浪徒 提交于 2019-12-11 08:47:17
问题 I wrote a code that reads multiple files, however on some of my files datetime swaps day & month whenever the day is less than 13, and any day that is from day 13 or above i.e. 13/06/11 remains correct (DD/MM/YY). I tried to fix it by doing this,but it doesn't work. My data frame looks like this: The actual datetime is from 12june2015 to 13june2015 when my I read my datetime column as a string the dates remain correct dd/mm/yyyy tmp p1 p2 11/06/2015 00:56:55.060 0 1 11/06/2015 04:16:38.060 0

Creating a multiindexed `Series` with a nested dictionary

╄→гoц情女王★ 提交于 2019-12-11 08:09:35
问题 In my mind, what I'm trying to do ought to be straightforward, as straightforward as passing it into the constructor, but in reality it's not. I have a dictionary like below. d = {"russell": {"score": numpy.random.rand(), "ping": numpy.random.randint(10, 100)}, "cantor": {"score": numpy.random.rand(), "ping": numpy.random.randint(10, 100)}, "godel": {"score": numpy.random.rand(), "ping": numpy.random.randint(10, 100)}} I would like to do something like pandas.Series(d) and get a Series