pandas: powerful Python data analysis toolkit - 0.25dtype='int32'), ...: 'E': pd.Categorical(["test", "train", "test", "train"]), ...: 'F': 'foo'}) ...: In [10]: df2 Out[10]: A B C D E F 0 1.0 2013-01-02 1.0 3 test foo 1 1.0 2013-01-02 1.0 3 train foo 2 1.0 dtypes. In [11]: df2.dtypes Out[11]: A float64 B datetime64[ns] C float32 D int32 E category F object dtype: object If youre using IPython, tab completion for column names (as well as public attributes) 2013-01-03 2 2013-01-04 3 2013-01-05 4 2013-01-06 5 2013-01-07 6 Freq: D, dtype: int64 In [47]: df['F'] = s1 Setting values by label: In [48]: df.at[dates[0], 'A'] = 0 Setting values by position: In0 码力 | 698 页 | 4.91 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 1.0.0------------------------------ RuntimeError Traceback (most recent call last)f4400a0c97> in ----> 1 mi.levels[0].name = "new name" /pandas/pandas/core/indexes/base.py in ------------------------------ ValueError Traceback (most recent call last) f04da2b3> in ----> 1 np.asarray(a, dtype="float") /opt/conda/envs/pandas/lib/python3.7/site /pandas/pandas/core/arrays/masked.py in to_numpy(self, dtype, copy, na_value) 122 ): 123 raise ValueError( --> 124 f"cannot convert to '{dtype}'-dtype NumPy array " 125 "with missing values. Specify an appropriate 'na_value' 0 码力 | 3015 页 | 10.78 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 0.25.1DataFrame([{'var1': 'a,b,c', 'var2': 1}, ....: {'var1': 'd,e,f', 'var2': 2}]) ....: In [13]: df Out[13]: var1 var2 0 a,b,c 1 1 d,e,f 2 [2 rows x 2 columns] Creating a long form DataFrame is now assign(var1=df.var1.str.split(',')).explode('var1') Out[14]: var1 var2 0 a 1 0 b 1 0 c 1 1 d 2 1 e 2 1 f 2 [6 rows x 2 columns] 1.1.7 Other enhancements • DataFrame.plot() keywords logy, logx and loglog dtype='int32'), ...: 'E': pd.Categorical(["test", "train", "test", "train"]), ...: 'F': 'foo'}) ...: In [10]: df2 Out[10]: A B C D E F 0 1.0 2013-01-02 1.0 3 test foo 1 1.0 2013-01-02 1.0 3 train foo 2 1.00 码力 | 2833 页 | 9.65 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 0.25.0DataFrame([{'var1': 'a,b,c', 'var2': 1}, ....: {'var1': 'd,e,f', 'var2': 2}]) ....: In [13]: df Out[13]: var1 var2 0 a,b,c 1 1 d,e,f 2 [2 rows x 2 columns] Creating a long form DataFrame is now assign(var1=df.var1.str.split(',')).explode('var1') Out[14]: var1 var2 0 a 1 0 b 1 0 c 1 1 d 2 1 e 2 1 f 2 [6 rows x 2 columns] 1.1.7 Other enhancements • DataFrame.plot() keywords logy, logx and loglog dtype='int32'), ...: 'E': pd.Categorical(["test", "train", "test", "train"]), ...: 'F': 'foo'}) ...: In [10]: df2 Out[10]: A B C D E F 0 1.0 2013-01-02 1.0 3 test foo 1 1.0 2013-01-02 1.0 3 train foo 2 1.00 码力 | 2827 页 | 9.62 MB | 1 年前3
pandas: powerful Python data analysis toolkit -1.0.3dtype='int32'), ...: 'E': pd.Categorical(["test", "train", "test", "train"]), ...: 'F': 'foo'}) ...: In [10]: df2 Out[10]: A B C D E F 0 1.0 2013-01-02 1.0 3 test foo 1 1.0 2013-01-02 1.0 3 train foo 2 1.0 dtypes. In [11]: df2.dtypes Out[11]: A float64 B datetime64[ns] C float32 D int32 E category F object dtype: object If you’re using IPython, tab completion for column names (as well as public attributes) 2013-01-03 2 2013-01-04 3 2013-01-05 4 2013-01-06 5 2013-01-07 6 Freq: D, dtype: int64 In [47]: df['F'] = s1 Setting values by label: In [48]: df.at[dates[0], 'A'] = 0 Setting values by position: 220 码力 | 3071 页 | 10.10 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 1.0dtype='int32'), ...: 'E': pd.Categorical(["test", "train", "test", "train"]), ...: 'F': 'foo'}) ...: In [10]: df2 Out[10]: A B C D E F 0 1.0 2013-01-02 1.0 3 test foo 1 1.0 2013-01-02 1.0 3 train foo 2 1.0 dtypes. In [11]: df2.dtypes Out[11]: A float64 B datetime64[ns] C float32 D int32 E category F object dtype: object If you’re using IPython, tab completion for column names (as well as public attributes) 2013-01-03 2 2013-01-04 3 2013-01-05 4 2013-01-06 5 2013-01-07 6 Freq: D, dtype: int64 In [47]: df['F'] = s1 Setting values by label: In [48]: df.at[dates[0], 'A'] = 0 20 Chapter 1. Getting started0 码力 | 3091 页 | 10.16 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 1.1.0“female” by “F” 1.4. Tutorials 57 pandas: powerful Python data analysis toolkit, Release 1.1.0 In [13]: titanic["Sex_short"] = titanic["Sex"].replace({"male": "M", ....: "female": "F"}) ....: In In [14]: titanic["Sex_short"] Out[14]: 0 M 1 F 2 F 3 F 4 M .. 886 M 887 F 888 F 889 M 890 M Name: Sex_short, Length: 891, dtype: object Whereas replace() is not a string method, it provides a of multiple values, this would become: titanic["Sex_short"] = titanic["Sex"].str.replace("female", "F") titanic["Sex_short"] = titanic["Sex_short"].str.replace("male", "M") This would become cumbersome0 码力 | 3229 页 | 10.87 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 0.13.1apply() operating on cross-sectional slabs. (GH1148) In [49]: f = lambda x: ((x.T-x.mean(1))/x.std(1)).T In [50]: result = panel.apply(f, axis = [’items’,’major_axis’]) In [51]: result Out[51]:f(panel.loc[:,:,ax])) ....: for ax in panel.minor_axis ])) ....: In [54]: result Out[54]: f) or table(t) the same defaults as prior < 0.13.0 remain, e.g. put implies fixed format and append implies 0 码力 | 1219 页 | 4.81 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 0.12position along the index) – A list or array of labels [’a’, ’b’, ’c’] – A slice object with labels ’a’:’f’, (note that contrary to usual python slices, both the start and the stop are included!) – A boolean DataFrame(randn(8, 6), index=date_range(’1/1/2000’, periods=8), ....: columns=[’A’, ’B’, ’C’, ’D’, ’E’, ’F’]) ....: In [28]: df_mt[’foo’] = ’bar’ # you can also create the tables individually In [29]: store analysis toolkit, Release 0.12.0 2000-01-08 -0.937772 -0.628728 In [32]: store.select(’df2_mt’) C D E F foo 2000-01-01 1.066971 -0.234118 -0.866424 0.058853 bar 2000-01-02 1.050428 -0.512589 -0.144609 -10 码力 | 657 页 | 3.58 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 1.0.4dtype='int32'), ...: 'E': pd.Categorical(["test", "train", "test", "train"]), ...: 'F': 'foo'}) ...: In [10]: df2 Out[10]: A B C D E F 0 1.0 2013-01-02 1.0 3 test foo 1 1.0 2013-01-02 1.0 3 train foo 2 1.0 dtypes. In [11]: df2.dtypes Out[11]: A float64 B datetime64[ns] C float32 D int32 E category F object dtype: object If you’re using IPython, tab completion for column names (as well as public attributes) 2013-01-03 2 2013-01-04 3 2013-01-05 4 2013-01-06 5 2013-01-07 6 Freq: D, dtype: int64 In [47]: df['F'] = s1 Setting values by label: In [48]: df.at[dates[0], 'A'] = 0 20 Chapter 1. Getting started0 码力 | 3081 页 | 10.24 MB | 1 年前3
共 32 条
- 1
- 2
- 3
- 4













