series

Convert Pandas series containing string to boolean

南笙酒味 提交于 2019-11-27 20:33:12
I have a DataFrame named df as Order Number Status 1 1668 Undelivered 2 19771 Undelivered 3 100032108 Undelivered 4 2229 Delivered 5 00056 Undelivered I would like to convert the Status column to boolean ( True when Status is Delivered and False when Status is Undelivered) but if Status is neither 'Undelivered' neither 'Delivered' it should be considered as NotANumber or something like that. I would like to use a dict d = { 'Delivered': True, 'Undelivered': False } so I could easily add other string which could be either considered as True or False . You can just use map : In [7]: df = pd

Convert pandas data frame to series

这一生的挚爱 提交于 2019-11-27 17:56:58
I'm somewhat new to pandas. I have a pandas data frame that is 1 row by 23 columns. I want to convert this into a series? I'm wondering what the most pythonic way to do this is? I've tried pd.Series(myResults) but it complains ValueError: cannot copy sequence with size 23 to array axis with dimension 1 . It's not smart enough to realize it's still a "vector" in math terms. Thanks! It's not smart enough to realize it's still a "vector" in math terms. Say rather that it's smart enough to recognize a difference in dimensionality. :-) I think the simplest thing you can do is select that row

Control column widths in a ggplot2 graph with a series and inconsistent data

依然范特西╮ 提交于 2019-11-27 15:48:21
In the artificial data I have created for the MWE below I have tried to demonstrate the essence of a script I have created in R. As can be seen by the graph that gets produced from this code, on one of my conditions I don't have a "No" value to complete the series. I have been told that unless I can make this last column that sadly doesn't have the extra series as thin as the columns else where in the graph I won't be permitted to use these graphs. This is sadly a problem because the script I have written produces hundreds of graphs simultaneously, complete with stats, significance indicators,

Get first element of Series without knowing the index [duplicate]

本小妞迷上赌 提交于 2019-11-27 14:18:10
问题 This question already has an answer here: Pandas - Get first row value of a given column 7 answers Is that any way that I can get first element of Seires without have information on index. For example,We have a Series import pandas as pd key='MCS096' SUBJECTS=pd.DataFrame({'ID':Series([146],index=[145]),\ 'study':Series(['MCS'],index=[145]),\ 'center':Series(['Mag'],index=[145]),\ 'initials':Series(['MCS096'],index=[145]) }) prints out SUBJECTS: print (SUBJECTS[SUBJECTS.initials==key]['ID'])

assigning column names to a pandas series

倾然丶 夕夏残阳落幕 提交于 2019-11-27 12:17:28
问题 I have a pandas series object x Ezh2 2 Hmgb 7 Irf1 1 I want to save this as a dataframe with column names Gene and Count respectively I tried x_df = pd.DataFrame(x,columns = ['Gene','count']) but it does not work.The final form I want is Gene Count Ezh2 2 Hmgb 7 Irf1 1 Can you suggest how to do this 回答1: You can create a dict and pass this as the data param to the dataframe constructor: In [235]: df = pd.DataFrame({'Gene':s.index, 'count':s.values}) df Out[235]: Gene count 0 Ezh2 2 1 Hmgb 7 2

Remove NaN from pandas series

时间秒杀一切 提交于 2019-11-27 12:16:14
Is there a way to remove a NaN values from a panda series? I have a series that may or may not have some NaN values in it, and I'd like to return a copy of the series with all the NaNs removed. Roman Pekar >>> s = pd.Series([1,2,3,4,np.NaN,5,np.NaN]) >>> s[~s.isnull()] 0 1 1 2 2 3 3 4 5 5 update or even better approach as @DSM suggested in comments, using pandas.Series.dropna() : >>> s.dropna() 0 1 1 2 2 3 3 4 5 5 A small usage of np.nan ! = np.nan s[s==s] Out[953]: 0 1.0 1 2.0 2 3.0 3 4.0 5 5.0 dtype: float64 More Info np.nan == np.nan Out[954]: False 来源: https://stackoverflow.com/questions

Elegant way to remove items from sequence in Python? [duplicate]

陌路散爱 提交于 2019-11-27 10:55:24
This question already has an answer here: How to remove items from a list while iterating? 26 answers When I am writing code in Python, I often need to remove items from a list or other sequence type based on some criteria. I haven't found a solution that is elegant and efficient, as removing items from a list you are currently iterating through is bad. For example, you can't do this: for name in names: if name[-5:] == 'Smith': names.remove(name) I usually end up doing something like this: toremove = [] for name in names: if name[-5:] == 'Smith': toremove.append(name) for name in toremove:

Chart series point added not sync with X axis

南笙酒味 提交于 2019-11-27 08:12:29
问题 I try to draw Chart via C# with table as picture. However, as you can see A4 data in date: 7 and 8/6 should stay with same 7 and 8/6 X-Axis, abnormal here all of them left to 5 & 6/6 X-Axis. Could you help me to fix it. for (int i = 0; i < 14; i++) { string productname = dataGridView1.Rows[i].Cells[0].Value.ToString(); string datetime = dataGridView1.Rows[i].Cells[2].Value.ToString(); int para = Convert.ToInt16(dataGridView1.Rows[i].Cells[1].Value); if (chart_dashboard.Series.IndexOf

Python Pandas concatenate a Series of strings into one string

↘锁芯ラ 提交于 2019-11-27 07:44:01
问题 In python pandas, there is a Series/dataframe column of str values to combine into one long string: df = pd.DataFrame({'text' : pd.Series(['Hello', 'world', '!'], index=['a', 'b', 'c'])}) Goal: 'Hello world !' Thus far methods such as df['text'].apply(lambda x: ' '.join(x)) are only returning the Series. What is the best way to get to the goal concatenated string? 回答1: You can join a string on the series directly: In [3]: ' '.join(df['text']) Out[3]: 'Hello world !' 回答2: Apart from join , you

Highcharts - Get crossing point of crossing series

青春壹個敷衍的年華 提交于 2019-11-27 07:17:13
问题 I am currently trying to extract the points of multiple crossings of series (a,b,c,d) of a specific series (x). I can't seem to find any function that can aid me in this task. My best bet is to measure the distance of every single point in x with every single point in a,b,c,d... and assume when the distance reaches under some threshold, the point must be a crossing point. I think this approach is far too computational heavy and seems "dirty". I believe there must be easier or better ways,