series

How to specify the type of pandas series elements in type hints?

非 Y 不嫁゛ 提交于 2020-05-12 20:32:36
问题 My function returns a pandas series, where all elements have a specific type (say str ). The following MWE should give an impression: import pandas as pd def f() -> pd.Series: return pd.Series(['a', 'b']) Within the type hints I want to make clear, that f()[0] will always be of type str (compared for example to a function that would return pd.Series([0, 1]) ). My initial guess was to use def f() -> pd.Series[str]: what gives the TypeError: 'type' object is not subscriptable . So, how to

How to specify the type of pandas series elements in type hints?

混江龙づ霸主 提交于 2020-05-12 20:29:15
问题 My function returns a pandas series, where all elements have a specific type (say str ). The following MWE should give an impression: import pandas as pd def f() -> pd.Series: return pd.Series(['a', 'b']) Within the type hints I want to make clear, that f()[0] will always be of type str (compared for example to a function that would return pd.Series([0, 1]) ). My initial guess was to use def f() -> pd.Series[str]: what gives the TypeError: 'type' object is not subscriptable . So, how to

Is there a query method or similar for pandas Series (pandas.Series.query())?

泄露秘密 提交于 2020-05-11 03:54:07
问题 The pandas.DataFrame.query() method is of great usage for (pre/post)-filtering data when loading or plotting. It comes particularly handy for method chaining. I find myself often wanting to apply the same logic to a pandas.Series , e.g. after having done a method such as df.value_counts which returns a pandas.Series . Example Lets assume there is a huge table with the columns Player, Game, Points and I want to plot a histogram of the players with more than 14 times 3 points. I first have to

Is there a query method or similar for pandas Series (pandas.Series.query())?

北城余情 提交于 2020-05-11 03:54:07
问题 The pandas.DataFrame.query() method is of great usage for (pre/post)-filtering data when loading or plotting. It comes particularly handy for method chaining. I find myself often wanting to apply the same logic to a pandas.Series , e.g. after having done a method such as df.value_counts which returns a pandas.Series . Example Lets assume there is a huge table with the columns Player, Game, Points and I want to plot a histogram of the players with more than 14 times 3 points. I first have to

What is the fastest and most efficient way to append rows to a DataFrame?

帅比萌擦擦* 提交于 2020-02-28 15:41:08
问题 I have a large dataset which I have to convert to .csv format, I have 29 columns and more than a million lines. I am using python and pandas dataframe to handle this job. I figured that as the dataframe gets larger, appending any rows to is it getting more and more time consuming. I wonder if there is any faster way to this, sharing the relevant snippet from the code. Any recommendations are welcome though. df = DataFrame() for startID in range(0, 100000, 1000): s1 = time.time() tempdf =

Delete rows if there are null values in a specific column in Pandas dataframe [duplicate]

こ雲淡風輕ζ 提交于 2020-02-17 12:48:47
问题 This question already has answers here : Python: How to drop a row whose particular column is empty/NaN? (2 answers) How to select rows from a DataFrame based on column values? (10 answers) Closed 2 years ago . Am new to python pandas. Need some help with deleting few rows where there are null values. In the screenshot, I need to delete rows where charge_per_line = - using python pandas. Thanks !! 回答1: If the relevant entries in Charge_Per_Line are empty ( NaN ) when you read into pandas, you

Delete rows if there are null values in a specific column in Pandas dataframe [duplicate]

孤街浪徒 提交于 2020-02-17 12:39:42
问题 This question already has answers here : Python: How to drop a row whose particular column is empty/NaN? (2 answers) How to select rows from a DataFrame based on column values? (10 answers) Closed 2 years ago . Am new to python pandas. Need some help with deleting few rows where there are null values. In the screenshot, I need to delete rows where charge_per_line = - using python pandas. Thanks !! 回答1: If the relevant entries in Charge_Per_Line are empty ( NaN ) when you read into pandas, you

C#/Excel: Working Around Maximum Series Size On Chart

怎甘沉沦 提交于 2020-02-13 02:23:42
问题 I need help programatically graphing more points than can fit in a single Excel series. According to http://office.microsoft.com/en-us/excel/HP100738491033.aspx the maximum number of points displayable on an Excel 2007 chart is 256000. Given that each series caps out at 32000 points, 8 series are required to plot the full 256000 points. My customer requires plotting of maximum amount of points per chart due to the large data sets we work with. I have moderate experience with C#/Excel interop

Difference between df[x], df[[x]], df['x'] , df[['x']] and df.x

微笑、不失礼 提交于 2020-01-30 04:41:15
问题 Struggling to understand the difference between the 5 examples in the title. Are some use cases for series vs. data frames? When should one be used over the other? Which are equivalent? 回答1: df[x] — index a column using variable x . Returns pd.Series df[[x]] — index/slice a single-column DataFrame using variable x . Returns pd.DataFrame df['x'] — index a column named 'x'. Returns pd.Series df[['x']] — index/slice a single-column DataFrame having only one column named 'x'. Returns pd.DataFrame

Add item to pandas.Series?

二次信任 提交于 2020-01-22 11:29:44
问题 I want to add an integer to my pandas.Series Here is my code: import pandas as pd input = pd.Series([1,2,3,4,5]) input.append(6) When i run this, i get the following error: Traceback (most recent call last): File "<pyshell#9>", line 1, in <module> f.append(6) File "C:\Python33\lib\site-packages\pandas\core\series.py", line 2047, in append verify_integrity=verify_integrity) File "C:\Python33\lib\site-packages\pandas\tools\merge.py", line 878, in concat verify_integrity=verify_integrity) File