2020-09-21

C:\Users\石悦政>
C:\Users\石悦政>cd f
系统找不到指定的路径。

C:\Users\石悦政>cd F:
F:\

C:\Users\石悦政>ipython
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)]
Type ‘copyright’, ‘credits’ or ‘license’ for more information
IPython 6.4.0 – An enhanced Interactive Python. Type ‘?’ for help.

In [1]: import pandas as ps

In [2]: import pandas as pd

In [3]: from pandas import Series

In [4]: from pandas import DataFrame

In [5]: s1 = Series(range(5))

In [6]: s1
Out[6]:
0 0
1 1
2 2
3 3
4 4
dtype: int64

In [7]: s2= Series (range(5),index=[‘a’,‘b’,‘c’,‘d’,‘e’])

In [8]: s2
Out[8]:
a 0
b 1
c 2
d 3
e 4
dtype: int64

In [9]: dic1={‘a’:1,‘b’:2,‘c’:3,‘d’:4}

In [10]: 地产

NameError Traceback (most recent call last)
in ()
----> 1 地产

NameError: name ‘地产’ is not defined

In [11]: dic1
Out[11]: {‘a’: 1, ‘b’: 2, ‘c’: 3, ‘d’: 4}

In [12]: s3=Series(dic1)

In [13]: s3
Out[13]:
a 1
b 2
c 3
d 4
dtype: int64

In [14]: s4=Series(dic1,index=[‘a’,‘b’])

In [15]: s4
Out[15]:
a 1
b 2
dtype: int64

In [16]: s1.index
Out[16]: RangeIndex(start=0, stop=5, step=1)

In [17]: s1.values
Out[17]: array([0, 1, 2, 3, 4], dtype=int64)

In [18]: s2.index
Out[18]: Index([‘a’, ‘b’, ‘c’, ‘d’, ‘e’], dtype=‘object’)

In [19]: s3([‘a’,‘b’])

TypeError Traceback (most recent call last)
in ()
----> 1 s3([‘a’,‘b’])

TypeError: ‘Series’ object is not callable

In [20]: s3
Out[20]:
a 1
b 2
c 3
d 4
dtype: int64

In [21]: s3[‘a’,‘b’]

TypeError Traceback (most recent call last)
D:\anaconda\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
3108 try:
-> 3109 return libindex.get_value_box(s, key)
3110 except IndexError:

pandas_libs\index.pyx in pandas._libs.index.get_value_box()

pandas_libs\index.pyx in pandas._libs.index.get_value_box()

TypeError: ‘tuple’ object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last)
in ()
----> 1 s3[‘a’,‘b’]

D:\anaconda\lib\site-packages\pandas\core\series.py in getitem(self, key)
764 key = com._apply_if_callable(key, self)
765 try:
–> 766 result = self.index.get_value(self, key)
767
768 if not is_scalar(result):

D:\anaconda\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
3115 raise InvalidIndexError(key)
3116 else:
-> 3117 raise e1
3118 except Exception: # pragma: no cover
3119 raise e1

D:\anaconda\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
3101 try:
3102 return self._engine.get_value(s, k,
-> 3103 tz=getattr(series.dtype, ‘tz’, None))
3104 except KeyError as e1:
3105 if len(self) > 0 and self.inferred_type in [‘integer’, ‘boolean’]:

pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: (‘a’, ‘b’)

In [22]: s3[1:3]
Out[22]:
b 2
c 3
dtype: int64

In [23]: s3(‘a’,‘b’)

TypeError Traceback (most recent call last)
in ()
----> 1 s3(‘a’,‘b’)

TypeError: ‘Series’ object is not callable

In [24]: s3(😃
File “”, line 1
s3(😃
^
SyntaxError: invalid syntax

In [25]: s3[:]
Out[25]:
a 1
b 2
c 3
d 4
dtype: int64

In [26]: s3(‘a’)

TypeError Traceback (most recent call last)
in ()
----> 1 s3(‘a’)

TypeError: ‘Series’ object is not callable

In [27]: s3(a)

NameError Traceback (most recent call last)
in ()
----> 1 s3(a)

NameError: name ‘a’ is not defined

In [28]: s3{‘a’}
File “”, line 1
s3{‘a’}
^
SyntaxError: invalid syntax

In [29]: s3[‘a’]
Out[29]: 1

In [30]: s3[‘a’,‘b’]

TypeError Traceback (most recent call last)
D:\anaconda\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
3108 try:
-> 3109 return libindex.get_value_box(s, key)
3110 except IndexError:

pandas_libs\index.pyx in pandas._libs.index.get_value_box()

pandas_libs\index.pyx in pandas._libs.index.get_value_box()

TypeError: ‘tuple’ object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last)
in ()
----> 1 s3[‘a’,‘b’]

D:\anaconda\lib\site-packages\pandas\core\series.py in getitem(self, key)
764 key = com._apply_if_callable(key, self)
765 try:
–> 766 result = self.index.get_value(self, key)
767
768 if not is_scalar(result):

D:\anaconda\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
3115 raise InvalidIndexError(key)
3116 else:
-> 3117 raise e1
3118 except Exception: # pragma: no cover
3119 raise e1

D:\anaconda\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
3101 try:
3102 return self._engine.get_value(s, k,
-> 3103 tz=getattr(series.dtype, ‘tz’, None))
3104 except KeyError as e1:
3105 if len(self) > 0 and self.inferred_type in [‘integer’, ‘boolean’]:

pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: (‘a’, ‘b’)

In [31]: s3[[‘a’,‘b’]]
Out[31]:
a 1
b 2
dtype: int64

In [32]: s1=Series([1,2,3,4])

In [33]: s2=Series([2,3,4,1])

In [34]: s1
Out[34]:
0 1
1 2
2 3
3 4
dtype: int64

In [35]: s2
Out[35]:
0 2
1 3
2 4
3 1
dtype: int64

In [36]: s1+s2
Out[36]:
0 3
1 5
2 7
3 5
dtype: int64

In [37]: s2*2
Out[37]:
0 4
1 6
2 8
3 2
dtype: int64

In [38]: s1*s2
Out[38]:
0 2
1 6
2 12
3 4
dtype: int64

In [39]: s1>=2
Out[39]:
0 False
1 True
2 True
3 True
dtype: bool

In [40]: In [17]:s1.add(s2)
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
…:
File “”, line 13
Out[6]:
^
SyntaxError: invalid syntax

In [41]: s1.add(s2)
Out[41]:
0 3
1 5
2 7
3 5
dtype: int64

In [42]: import numpy as ny

In [43]: np.arrange(9)

NameError Traceback (most recent call last)
in ()
----> 1 np.arrange(9)

NameError: name ‘np’ is not defined

In [44]: ny.arrange(9)

AttributeError Traceback (most recent call last)
in ()
----> 1 ny.arrange(9)

AttributeError: module ‘numpy’ has no attribute ‘arrange’

In [45]: import numpy as np

In [46]: np.arrange(9).reshape(3,3)

AttributeError Traceback (most recent call last)
in ()
----> 1 np.arrange(9).reshape(3,3)

AttributeError: module ‘numpy’ has no attribute ‘arrange’

In [47]: np.arange(9).reshape(3,3)
Out[47]:
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])

In [48]: a1=np.arange(9).reshape(3,3)

In [49]: df1=DataFrame(a1)

In [50]: df1
Out[50]:
0 1 2
0 0 1 2
1 3 4 5
2 6 7 8

In [51]: df1 = DataFrame(a1.index=[1,2,3],columns=[‘a’,‘b’,‘c’])
File “”, line 1
df1 = DataFrame(a1.index=[1,2,3],columns=[‘a’,‘b’,‘c’])
^
SyntaxError: keyword can’t be an expression

In [52]: df_tinct=pd.read_csv(’./data/bikes.csv’)

FileNotFoundError Traceback (most recent call last)
in ()
----> 1 df_tinct=pd.read_csv(’./data/bikes.csv’)

D:\anaconda\lib\site-packages\pandas\io\parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, doublequote, delim_whitespace, low_memory, memory_map, float_precision)
676 skip_blank_lines=skip_blank_lines)
677
–> 678 return _read(filepath_or_buffer, kwds)
679
680 parser_f.name = name

D:\anaconda\lib\site-packages\pandas\io\parsers.py in _read(filepath_or_buffer, kwds)
438
439 # Create the parser.
–> 440 parser = TextFileReader(filepath_or_buffer, **kwds)
441
442 if chunksize or iterator:

D:\anaconda\lib\site-packages\pandas\io\parsers.py in init(self, f, engine, **kwds)
785 self.options[‘has_index_names’] = kwds[‘has_index_names’]
786
–> 787 self._make_engine(self.engine)
788
789 def close(self):

D:\anaconda\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine)
1012 def _make_engine(self, engine=‘c’):
1013 if engine == ‘c’:
-> 1014 self._engine = CParserWrapper(self.f, **self.options)
1015 else:
1016 if engine == ‘python’:

D:\anaconda\lib\site-packages\pandas\io\parsers.py in init(self, src, **kwds)
1706 kwds[‘usecols’] = self.usecols
1707
-> 1708 self._reader = parsers.TextReader(src, **kwds)
1709
1710 passed_names = self.names is None

pandas_libs\parsers.pyx in pandas._libs.parsers.TextReader.cinit()

pandas_libs\parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source()

FileNotFoundError: File b’./data/bikes.csv’ does not exist

In [53]: df_bikes=pd.read_csv(’./bikes.csv’)

UnicodeDecodeError Traceback (most recent call last)
in ()
----> 1 df_bikes=pd.read_csv(’./bikes.csv’)

D:\anaconda\lib\site-packages\pandas\io\parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, doublequote, delim_whitespace, low_memory, memory_map, float_precision)
676 skip_blank_lines=skip_blank_lines)
677
–> 678 return _read(filepath_or_buffer, kwds)
679
680 parser_f.name = name

D:\anaconda\lib\site-packages\pandas\io\parsers.py in _read(filepath_or_buffer, kwds)
438
439 # Create the parser.
–> 440 parser = TextFileReader(filepath_or_buffer, **kwds)
441
442 if chunksize or iterator:

D:\anaconda\lib\site-packages\pandas\io\parsers.py in init(self, f, engine, **kwds)
785 self.options[‘has_index_names’] = kwds[‘has_index_names’]
786
–> 787 self._make_engine(self.engine)
788
789 def close(self):

D:\anaconda\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine)
1012 def _make_engine(self, engine=‘c’):
1013 if engine == ‘c’:
-> 1014 self._engine = CParserWrapper(self.f, **self.options)
1015 else:
1016 if engine == ‘python’:

D:\anaconda\lib\site-packages\pandas\io\parsers.py in init(self, src, **kwds)
1706 kwds[‘usecols’] = self.usecols
1707
-> 1708 self._reader = parsers.TextReader(src, **kwds)
1709
1710 passed_names = self.names is None

pandas_libs\parsers.pyx in pandas._libs.parsers.TextReader.cinit()

pandas_libs\parsers.pyx in pandas._libs.parsers.TextReader._get_header()

UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xe9 in position 15: invalid continuation byte

In [54]: df_bikes=pd.read_csv(‘bikes.csv’)

UnicodeDecodeError Traceback (most recent call last)
in ()
----> 1 df_bikes=pd.read_csv(‘bikes.csv’)

D:\anaconda\lib\site-packages\pandas\io\parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, doublequote, delim_whitespace, low_memory, memory_map, float_precision)
676 skip_blank_lines=skip_blank_lines)
677
–> 678 return _read(filepath_or_buffer, kwds)
679
680 parser_f.name = name

D:\anaconda\lib\site-packages\pandas\io\parsers.py in _read(filepath_or_buffer, kwds)
438
439 # Create the parser.
–> 440 parser = TextFileReader(filepath_or_buffer, **kwds)
441
442 if chunksize or iterator:

D:\anaconda\lib\site-packages\pandas\io\parsers.py in init(self, f, engine, **kwds)
785 self.options[‘has_index_names’] = kwds[‘has_index_names’]
786
–> 787 self._make_engine(self.engine)
788
789 def close(self):

D:\anaconda\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine)
1012 def _make_engine(self, engine=‘c’):
1013 if engine == ‘c’:
-> 1014 self._engine = CParserWrapper(self.f, **self.options)
1015 else:
1016 if engine == ‘python’:

D:\anaconda\lib\site-packages\pandas\io\parsers.py in init(self, src, **kwds)
1706 kwds[‘usecols’] = self.usecols
1707
-> 1708 self._reader = parsers.TextReader(src, **kwds)
1709
1710 passed_names = self.names is None

pandas_libs\parsers.pyx in pandas._libs.parsers.TextReader.cinit()

pandas_libs\parsers.pyx in pandas._libs.parsers.TextReader._get_header()

UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xe9 in position 15: invalid continuation byte

In [55]: df_bikes=pd.read_csv(’./bikes.csv’)

UnicodeDecodeError Traceback (most recent call last)
in ()
----> 1 df_bikes=pd.read_csv(’./bikes.csv’)

D:\anaconda\lib\site-packages\pandas\io\parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, doublequote, delim_whitespace, low_memory, memory_map, float_precision)
676 skip_blank_lines=skip_blank_lines)
677
–> 678 return _read(filepath_or_buffer, kwds)
679
680 parser_f.name = name

D:\anaconda\lib\site-packages\pandas\io\parsers.py in _read(filepath_or_buffer, kwds)
438
439 # Create the parser.
–> 440 parser = TextFileReader(filepath_or_buffer, **kwds)
441
442 if chunksize or iterator:

D:\anaconda\lib\site-packages\pandas\io\parsers.py in init(self, f, engine, **kwds)
785 self.options[‘has_index_names’] = kwds[‘has_index_names’]
786
–> 787 self._make_engine(self.engine)
788
789 def close(self):

D:\anaconda\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine)
1012 def _make_engine(self, engine=‘c’):
1013 if engine == ‘c’:
-> 1014 self._engine = CParserWrapper(self.f, **self.options)
1015 else:
1016 if engine == ‘python’:

D:\anaconda\lib\site-packages\pandas\io\parsers.py in init(self, src, **kwds)
1706 kwds[‘usecols’] = self.usecols
1707
-> 1708 self._reader = parsers.TextReader(src, **kwds)
1709
1710 passed_names = self.names is None

pandas_libs\parsers.pyx in pandas._libs.parsers.TextReader.cinit()

pandas_libs\parsers.pyx in pandas._libs.parsers.TextReader._get_header()

UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xe9 in position 15: invalid continuation byte

In [56]: df_tinct = pd.read_csv(‘bicks.csv’,encoding=‘jbk’)

FileNotFoundError Traceback (most recent call last)
in ()
----> 1 df_tinct = pd.read_csv(‘bicks.csv’,encoding=‘jbk’)

D:\anaconda\lib\site-packages\pandas\io\parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, doublequote, delim_whitespace, low_memory, memory_map, float_precision)
676 skip_blank_lines=skip_blank_lines)
677
–> 678 return _read(filepath_or_buffer, kwds)
679
680 parser_f.name = name

D:\anaconda\lib\site-packages\pandas\io\parsers.py in _read(filepath_or_buffer, kwds)
438
439 # Create the parser.
–> 440 parser = TextFileReader(filepath_or_buffer, **kwds)
441
442 if chunksize or iterator:

D:\anaconda\lib\site-packages\pandas\io\parsers.py in init(self, f, engine, **kwds)
785 self.options[‘has_index_names’] = kwds[‘has_index_names’]
786
–> 787 self._make_engine(self.engine)
788
789 def close(self):

D:\anaconda\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine)
1012 def _make_engine(self, engine=‘c’):
1013 if engine == ‘c’:
-> 1014 self._engine = CParserWrapper(self.f, **self.options)
1015 else:
1016 if engine == ‘python’:

D:\anaconda\lib\site-packages\pandas\io\parsers.py in init(self, src, **kwds)
1706 kwds[‘usecols’] = self.usecols
1707
-> 1708 self._reader = parsers.TextReader(src, **kwds)
1709
1710 passed_names = self.names is None

pandas_libs\parsers.pyx in pandas._libs.parsers.TextReader.cinit()

pandas_libs\parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source()

FileNotFoundError: File b’bicks.csv’ does not exist

In [57]: df_tinct = pd.read_csv(‘bikes.csv’,encoding=‘jbk’)

LookupError Traceback (most recent call last)
in ()
----> 1 df_tinct = pd.read_csv(‘bikes.csv’,encoding=‘jbk’)

D:\anaconda\lib\site-packages\pandas\io\parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, doublequote, delim_whitespace, low_memory, memory_map, float_precision)
676 skip_blank_lines=skip_blank_lines)
677
–> 678 return _read(filepath_or_buffer, kwds)
679
680 parser_f.name = name

D:\anaconda\lib\site-packages\pandas\io\parsers.py in _read(filepath_or_buffer, kwds)
438
439 # Create the parser.
–> 440 parser = TextFileReader(filepath_or_buffer, **kwds)
441
442 if chunksize or iterator:

D:\anaconda\lib\site-packages\pandas\io\parsers.py in init(self, f, engine, **kwds)
785 self.options[‘has_index_names’] = kwds[‘has_index_names’]
786
–> 787 self._make_engine(self.engine)
788
789 def close(self):

D:\anaconda\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine)
1012 def _make_engine(self, engine=‘c’):
1013 if engine == ‘c’:
-> 1014 self._engine = CParserWrapper(self.f, **self.options)
1015 else:
1016 if engine == ‘python’:

D:\anaconda\lib\site-packages\pandas\io\parsers.py in init(self, src, **kwds)
1706 kwds[‘usecols’] = self.usecols
1707
-> 1708 self._reader = parsers.TextReader(src, **kwds)
1709
1710 passed_names = self.names is None

pandas_libs\parsers.pyx in pandas._libs.parsers.TextReader.cinit()

pandas_libs\parsers.pyx in pandas._libs.parsers.TextReader._get_header()

LookupError: unknown encoding: jbk

In [58]: df_tinct = pd.read_csv(‘bikes.csv’,encoding=‘gbk’)

In [59]: df_tinct
Out[59]:
Date;Berri 1;Br閎euf (donn閑s non disponibles);C魌e-Sainte-Catherine;Maisonneuve 1;Maisonneuve 2;du Parc;Pierre-Dupuy;Rachel1;St-Urbain (donn閑s non disponibles)
0 01/01/2012;35;;0;38;51;26;10;16;
1 02/01/2012;83;;1;68;153;53;6;43;
2 03/01/2012;135;;2;104;248;89;3;58;
3 04/01/2012;144;;1;116;318;111;8;61;
4 05/01/2012;197;;2;124;330;97;13;95;
5 06/01/2012;146;;0;98;244;86;4;75;
6 07/01/2012;98;;2;80;108;53;6;54;
7 08/01/2012;95;;1;62;98;64;11;63;
8 09/01/2012;244;;2;165;432;198;12;173;
9 10/01/2012;397;;3;238;563;275;18;241;
10 11/01/2012;273;;0;182;443;258;12;194;
11 12/01/2012;157;;1;134;261;137;9;63;
12 13/01/2012;75;;0;41;105;64;2;0;
13 14/01/2012;32;;0;54;56;19;0;1;
14 15/01/2012;54;;0;33;60;18;0;0;
15 16/01/2012;168;;2;136;312;137;1;0
16 17/01/2012;155;;0;86;256;74;0;0
17 18/01/2012;139;;0;66;188;68;3;0
18 19/01/2012;191;;1;104;248;79;3;0
19 20/01/2012;161;;4;96;217;67;1;1
20 21/01/2012;53;;0;47;70;32;1;0
21 22/01/2012;71;;0;41;73;35;5;0
22 23/01/2012;210;;6;114;357;91;6;0
23 24/01/2012;299;;1;189;444;174;4;0
24 25/01/2012;334;;1;217;453;180;4;0
25 26/01/2012;306;;0;215;495;191;0;1
26 27/01/2012;91;;5;79;204;65;0;0
27 28/01/2012;80;;1;61;123;33;9;1
28 29/01/2012;87;;1;65;132;40;7;0
29 30/01/2012;219;;0;146;371;152;2;0
… …
280 07/10/2012;1580;;660;922;1629;860;695;2052
281 08/10/2012;1854;;880;987;1818;1040;1115;2502
282 09/10/2012;4787;;2210;3026;5138;3418;927;4078
283 10/10/2012;3115;;1537;2081;3681;2608;560;2703
284 11/10/2012;3746;;1857;2569;4694;3034;558;3457
285 12/10/2012;3169;;1460;2261;4045;2564;448;3224
286 13/10/2012;1783;;802;1205;2113;1183;681;2309
287 14/10/2012;587;;287;443;852;503;65;952
288 15/10/2012;3292;;1678;2165;4197;2754;560;3183
289 16/10/2012;3739;;1858;2684;4681;2997;554;3593
290 17/10/2012;4098;;1964;2645;4836;3063;728;3834
291 18/10/2012;4671;;2292;3129;5542;3477;1108;4245
292 19/10/2012;1313;;597;885;1668;1209;111;1486
293 20/10/2012;2011;;748;1323;2266;1213;797;2243
294 21/10/2012;1277;;609;869;1777;898;242;1648
295 22/10/2012;3650;;1819;2495;4800;3023;757;3721
296 23/10/2012;4177;;1997;2795;5216;3233;795;3554
297 24/10/2012;3744;;1868;2625;4900;3035;649;3622
298 25/10/2012;3735;;1815;2528;5010;3017;631;3767
299 26/10/2012;4290;;1987;2754;5246;3000;1456;4578
300 27/10/2012;1857;;792;1244;2461;1193;618;2471
301 28/10/2012;1310;;697;910;1776;955;387;1876
302 29/10/2012;2919;;1458;2071;3768;2440;411;2795
303 30/10/2012;2887;;1251;2007;3516;2255;338;2790
304 31/10/2012;2634;;1294;1835;3453;2220;245;2570
305 01/11/2012;2405;;1208;1701;3082;2076;165;2461
306 02/11/2012;1582;;737;1109;2277;1392;97;1888
307 03/11/2012;844;;380;612;1137;713;105;1302
308 04/11/2012;966;;446;710;1277;692;197;1374
309 05/11/2012;2247;;1170;1705;3221;2143;179;2430

[310 rows x 1 columns]

In [60]: df_bikes.info()

NameError Traceback (most recent call last)
in ()
----> 1 df_bikes.info()

NameError: name ‘df_bikes’ is not defined

In [61]: df_tinct.info()
<class ‘pandas.core.frame.DataFrame’>
RangeIndex: 310 entries, 0 to 309
Data columns (total 1 columns):
Date;Berri 1;Br閎euf (donn閑s non disponibles);C魌e-Sainte-Catherine;Maisonneuve 1;Maisonneuve 2;du Parc;Pierre-Dupuy;Rachel1;St-Urbain (donn閑s non disponibles) 310 non-null object
dtypes: object(1)
memory usage: 2.5+ KB

In [62]: df_tinct
Out[62]:
Date;Berri 1;Br閎euf (donn閑s non disponibles);C魌e-Sainte-Catherine;Maisonneuve 1;Maisonneuve 2;du Parc;Pierre-Dupuy;Rachel1;St-Urbain (donn閑s non disponibles)
0 01/01/2012;35;;0;38;51;26;10;16;
1 02/01/2012;83;;1;68;153;53;6;43;
2 03/01/2012;135;;2;104;248;89;3;58;
3 04/01/2012;144;;1;116;318;111;8;61;
4 05/01/2012;197;;2;124;330;97;13;95;
5 06/01/2012;146;;0;98;244;86;4;75;
6 07/01/2012;98;;2;80;108;53;6;54;
7 08/01/2012;95;;1;62;98;64;11;63;
8 09/01/2012;244;;2;165;432;198;12;173;
9 10/01/2012;397;;3;238;563;275;18;241;
10 11/01/2012;273;;0;182;443;258;12;194;
11 12/01/2012;157;;1;134;261;137;9;63;
12 13/01/2012;75;;0;41;105;64;2;0;
13 14/01/2012;32;;0;54;56;19;0;1;
14 15/01/2012;54;;0;33;60;18;0;0;
15 16/01/2012;168;;2;136;312;137;1;0
16 17/01/2012;155;;0;86;256;74;0;0
17 18/01/2012;139;;0;66;188;68;3;0
18 19/01/2012;191;;1;104;248;79;3;0
19 20/01/2012;161;;4;96;217;67;1;1
20 21/01/2012;53;;0;47;70;32;1;0
21 22/01/2012;71;;0;41;73;35;5;0
22 23/01/2012;210;;6;114;357;91;6;0
23 24/01/2012;299;;1;189;444;174;4;0
24 25/01/2012;334;;1;217;453;180;4;0
25 26/01/2012;306;;0;215;495;191;0;1
26 27/01/2012;91;;5;79;204;65;0;0
27 28/01/2012;80;;1;61;123;33;9;1
28 29/01/2012;87;;1;65;132;40;7;0
29 30/01/2012;219;;0;146;371;152;2;0
… …
280 07/10/2012;1580;;660;922;1629;860;695;2052
281 08/10/2012;1854;;880;987;1818;1040;1115;2502
282 09/10/2012;4787;;2210;3026;5138;3418;927;4078
283 10/10/2012;3115;;1537;2081;3681;2608;560;2703
284 11/10/2012;3746;;1857;2569;4694;3034;558;3457
285 12/10/2012;3169;;1460;2261;4045;2564;448;3224
286 13/10/2012;1783;;802;1205;2113;1183;681;2309
287 14/10/2012;587;;287;443;852;503;65;952
288 15/10/2012;3292;;1678;2165;4197;2754;560;3183
289 16/10/2012;3739;;1858;2684;4681;2997;554;3593
290 17/10/2012;4098;;1964;2645;4836;3063;728;3834
291 18/10/2012;4671;;2292;3129;5542;3477;1108;4245
292 19/10/2012;1313;;597;885;1668;1209;111;1486
293 20/10/2012;2011;;748;1323;2266;1213;797;2243
294 21/10/2012;1277;;609;869;1777;898;242;1648
295 22/10/2012;3650;;1819;2495;4800;3023;757;3721
296 23/10/2012;4177;;1997;2795;5216;3233;795;3554
297 24/10/2012;3744;;1868;2625;4900;3035;649;3622
298 25/10/2012;3735;;1815;2528;5010;3017;631;3767
299 26/10/2012;4290;;1987;2754;5246;3000;1456;4578
300 27/10/2012;1857;;792;1244;2461;1193;618;2471
301 28/10/2012;1310;;697;910;1776;955;387;1876
302 29/10/2012;2919;;1458;2071;3768;2440;411;2795
303 30/10/2012;2887;;1251;2007;3516;2255;338;2790
304 31/10/2012;2634;;1294;1835;3453;2220;245;2570
305 01/11/2012;2405;;1208;1701;3082;2076;165;2461
306 02/11/2012;1582;;737;1109;2277;1392;97;1888
307 03/11/2012;844;;380;612;1137;713;105;1302
308 04/11/2012;966;;446;710;1277;692;197;1374
309 05/11/2012;2247;;1170;1705;3221;2143;179;2430

[310 rows x 1 columns]

In [63]: df_tinct1 = pd.read_csv(‘tinct.csv’)

FileNotFoundError Traceback (most recent call last)
in ()
----> 1 df_tinct1 = pd.read_csv(‘tinct.csv’)

D:\anaconda\lib\site-packages\pandas\io\parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, doublequote, delim_whitespace, low_memory, memory_map, float_precision)
676 skip_blank_lines=skip_blank_lines)
677
–> 678 return _read(filepath_or_buffer, kwds)
679
680 parser_f.name = name

D:\anaconda\lib\site-packages\pandas\io\parsers.py in _read(filepath_or_buffer, kwds)
438
439 # Create the parser.
–> 440 parser = TextFileReader(filepath_or_buffer, **kwds)
441
442 if chunksize or iterator:

D:\anaconda\lib\site-packages\pandas\io\parsers.py in init(self, f, engine, **kwds)
785 self.options[‘has_index_names’] = kwds[‘has_index_names’]
786
–> 787 self._make_engine(self.engine)
788
789 def close(self):

D:\anaconda\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine)
1012 def _make_engine(self, engine=‘c’):
1013 if engine == ‘c’:
-> 1014 self._engine = CParserWrapper(self.f, **self.options)
1015 else:
1016 if engine == ‘python’:

D:\anaconda\lib\site-packages\pandas\io\parsers.py in init(self, src, **kwds)
1706 kwds[‘usecols’] = self.usecols
1707
-> 1708 self._reader = parsers.TextReader(src, **kwds)
1709
1710 passed_names = self.names is None

pandas_libs\parsers.pyx in pandas._libs.parsers.TextReader.cinit()

pandas_libs\parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source()

FileNotFoundError: File b’tinct.csv’ does not exist

In [64]: df_tinct1 = pd.read_csv(‘titanic.csv’)

In [65]: df_tinct1
Out[65]:
乘客ID 是否获救 船舱等级 … 价格 编号 登船地点
0 PassengerId Survived Pclass … Fare Cabin Embarked
1 1 0 3 … 7.25 NaN S
2 2 1 1 … 71.2833 C85 C
3 3 1 3 … 7.925 NaN S
4 4 1 1 … 53.1 C123 S
5 5 0 3 … 8.05 NaN S
6 6 0 3 … 8.4583 NaN Q
7 7 0 1 … 51.8625 E46 S
8 8 0 3 … 21.075 NaN S
9 9 1 3 … 11.1333 NaN S
10 10 1 2 … 30.0708 NaN C
11 11 1 3 … 16.7 G6 S
12 12 1 1 … 26.55 C103 S
13 13 0 3 … 8.05 NaN S
14 14 0 3 … 31.275 NaN S
15 15 0 3 … 7.8542 NaN S
16 16 1 2 … 16 NaN S
17 17 0 3 … 29.125 NaN Q
18 18 1 2 … 13 NaN S
19 19 0 3 … 18 NaN S
20 20 1 3 … 7.225 NaN C
21 21 0 2 … 26 NaN S
22 22 1 2 … 13 D56 S
23 23 1 3 … 8.0292 NaN Q
24 24 1 1 … 35.5 A6 S
25 25 0 3 … 21.075 NaN S
26 26 1 3 … 31.3875 NaN S
27 27 0 3 … 7.225 NaN C
28 28 0 1 … 263 C23 C25 C27 S
29 29 1 3 … 7.8792 NaN Q
… … … … … … … …
862 862 0 2 … 11.5 NaN S
863 863 1 1 … 25.9292 D17 S
864 864 0 3 … 69.55 NaN S
865 865 0 2 … 13 NaN S
866 866 1 2 … 13 NaN S
867 867 1 2 … 13.8583 NaN C
868 868 0 1 … 50.4958 A24 S
869 869 0 3 … 9.5 NaN S
870 870 1 3 … 11.1333 NaN S
871 871 0 3 … 7.8958 NaN S
872 872 1 1 … 52.5542 D35 S
873 873 0 1 … 5 B51 B53 B55 S
874 874 0 3 … 9 NaN S
875 875 1 2 … 24 NaN C
876 876 1 3 … 7.225 NaN C
877 877 0 3 … 9.8458 NaN S
878 878 0 3 … 7.8958 NaN S
879 879 0 3 … 7.8958 NaN S
880 880 1 1 … 83.1583 C50 C
881 881 1 2 … 26 NaN S
882 882 0 3 … 7.8958 NaN S
883 883 0 3 … 10.5167 NaN S
884 884 0 2 … 10.5 NaN S
885 885 0 3 … 7.05 NaN S
886 886 0 3 … 29.125 NaN Q
887 887 0 2 … 13 NaN S
888 888 1 1 … 30 B42 S
889 889 0 3 … 23.45 NaN S
890 890 1 1 … 30 C148 C
891 891 0 3 … 7.75 NaN Q

[892 rows x 12 columns]

In [66]: df1
Out[66]:
0 1 2
0 0 1 2
1 3 4 5
2 6 7 8

In [67]: df1[1:2,2:3]

TypeError Traceback (most recent call last)
in ()
----> 1 df1[1:2,2:3]

D:\anaconda\lib\site-packages\pandas\core\frame.py in getitem(self, key)
2683 return self._getitem_multilevel(key)
2684 else:
-> 2685 return self._getitem_column(key)
2686
2687 def _getitem_column(self, key):

D:\anaconda\lib\site-packages\pandas\core\frame.py in _getitem_column(self, key)
2690 # get column
2691 if self.columns.is_unique:
-> 2692 return self._get_item_cache(key)
2693
2694 # duplicate columns & possible reduce dimensionality

D:\anaconda\lib\site-packages\pandas\core\generic.py in _get_item_cache(self, item)
2482 “”“Return the cached item, item represents a label indexer.”""
2483 cache = self._item_cache
-> 2484 res = cache.get(item)
2485 if res is None:
2486 values = self._data.get(item)

TypeError: unhashable type: ‘slice’

In [68]: df1[1:2,1:@]
File “”, line 1
df1[1:2,1:@]
^
SyntaxError: invalid syntax

In [69]: df1[1:2,1:2]

TypeError Traceback (most recent call last)
in ()
----> 1 df1[1:2,1:2]

D:\anaconda\lib\site-packages\pandas\core\frame.py in getitem(self, key)
2683 return self._getitem_multilevel(key)
2684 else:
-> 2685 return self._getitem_column(key)
2686
2687 def _getitem_column(self, key):

D:\anaconda\lib\site-packages\pandas\core\frame.py in _getitem_column(self, key)
2690 # get column
2691 if self.columns.is_unique:
-> 2692 return self._get_item_cache(key)
2693
2694 # duplicate columns & possible reduce dimensionality

D:\anaconda\lib\site-packages\pandas\core\generic.py in _get_item_cache(self, item)
2482 “”“Return the cached item, item represents a label indexer.”""
2483 cache = self._item_cache
-> 2484 res = cache.get(item)
2485 if res is None:
2486 values = self._data.get(item)

TypeError: unhashable type: ‘slice’

In [70]: df1[1:2,0:1]

TypeError Traceback (most recent call last)
in ()
----> 1 df1[1:2,0:1]

D:\anaconda\lib\site-packages\pandas\core\frame.py in getitem(self, key)
2683 return self._getitem_multilevel(key)
2684 else:
-> 2685 return self._getitem_column(key)
2686
2687 def _getitem_column(self, key):

D:\anaconda\lib\site-packages\pandas\core\frame.py in _getitem_column(self, key)
2690 # get column
2691 if self.columns.is_unique:
-> 2692 return self._get_item_cache(key)
2693
2694 # duplicate columns & possible reduce dimensionality

D:\anaconda\lib\site-packages\pandas\core\generic.py in _get_item_cache(self, item)
2482 “”“Return the cached item, item represents a label indexer.”""
2483 cache = self._item_cache
-> 2484 res = cache.get(item)
2485 if res is None:
2486 values = self._data.get(item)

TypeError: unhashable type: ‘slice’

In [71]: df1.iloc[1:2,0:1]
Out[71]:
0
1 3

In [72]: df1.iloc[1:2,0:2]
Out[72]:
0 1
1 3 4

In [73]: df1
Out[73]:
0 1 2
0 0 1 2
1 3 4 5
2 6 7 8

In [74]: df1
Out[74]:
0 1 2
0 0 1 2
1 3 4 5
2 6 7 8

In [75]: df1.loc[1:2,0:2]
Out[75]:
0 1 2
1 3 4 5
2 6 7 8

In [76]: df_tinct(‘sex’)[‘Age’].mean()

TypeError Traceback (most recent call last)
in ()
----> 1 df_tinct(‘sex’)[‘Age’].mean()

TypeError: ‘DataFrame’ object is not callable

In [77]:

In [77]: df_tinct1(‘sex’)[‘Age’].mean()

TypeError Traceback (most recent call last)
in ()
----> 1 df_tinct1(‘sex’)[‘Age’].mean()

TypeError: ‘DataFrame’ object is not callable

In [78]: df_tinct1.groupby(‘sex’)[‘Age’].mean()

KeyError Traceback (most recent call last)
in ()
----> 1 df_tinct1.groupby(‘sex’)[‘Age’].mean()

D:\anaconda\lib\site-packages\pandas\core\generic.py in groupby(self, by, axis, level, as_index, sort, group_keys, squeeze, observed, **kwargs)
6657 return groupby(self, by=by, axis=axis, level=level, as_index=as_index,
6658 sort=sort, group_keys=group_keys, squeeze=squeeze,
-> 6659 observed=observed, **kwargs)
6660
6661 def asfreq(self, freq, method=None, how=None, normalize=False,

D:\anaconda\lib\site-packages\pandas\core\groupby\groupby.py in groupby(obj, by, **kwds)
2150 raise TypeError(‘invalid type: %s’ % type(obj))
2151
-> 2152 return klass(obj, by, **kwds)
2153
2154

D:\anaconda\lib\site-packages\pandas\core\groupby\groupby.py in init(self, obj, keys, axis, level, grouper, exclusions, selection, as_index, sort, group_keys, squeeze, observed, **kwargs)
597 sort=sort,
598 observed=observed,
–> 599 mutated=self.mutated)
600
601 self.obj = obj

D:\anaconda\lib\site-packages\pandas\core\groupby\groupby.py in _get_grouper(obj, key, axis, level, sort, observed, mutated, validate)
3289 in_axis, name, level, gpr = False, None, gpr, None
3290 else:
-> 3291 raise KeyError(gpr)
3292 elif isinstance(gpr, Grouper) and gpr.key is not None:
3293 # Add key to exclusions

KeyError: ‘sex’

In [79]: df_tinct1.groupby(‘Sex’)[‘Age’].mean()

KeyError Traceback (most recent call last)
in ()
----> 1 df_tinct1.groupby(‘Sex’)[‘Age’].mean()

D:\anaconda\lib\site-packages\pandas\core\generic.py in groupby(self, by, axis, level, as_index, sort, group_keys, squeeze, observed, **kwargs)
6657 return groupby(self, by=by, axis=axis, level=level, as_index=as_index,
6658 sort=sort, group_keys=group_keys, squeeze=squeeze,
-> 6659 observed=observed, **kwargs)
6660
6661 def asfreq(self, freq, method=None, how=None, normalize=False,

D:\anaconda\lib\site-packages\pandas\core\groupby\groupby.py in groupby(obj, by, **kwds)
2150 raise TypeError(‘invalid type: %s’ % type(obj))
2151
-> 2152 return klass(obj, by, **kwds)
2153
2154

D:\anaconda\lib\site-packages\pandas\core\groupby\groupby.py in init(self, obj, keys, axis, level, grouper, exclusions, selection, as_index, sort, group_keys, squeeze, observed, **kwargs)
597 sort=sort,
598 observed=observed,
–> 599 mutated=self.mutated)
600
601 self.obj = obj

D:\anaconda\lib\site-packages\pandas\core\groupby\groupby.py in _get_grouper(obj, key, axis, level, sort, observed, mutated, validate)
3289 in_axis, name, level, gpr = False, None, gpr, None
3290 else:
-> 3291 raise KeyError(gpr)
3292 elif isinstance(gpr, Grouper) and gpr.key is not None:
3293 # Add key to exclusions

KeyError: ‘Sex’

In [80]: df_tinct1
Out[80]:
乘客ID 是否获救 船舱等级 名字 … 船票 价格 编号 登船地点
0 PassengerId Survived Pclass Name … Ticket Fare Cabin Embarked
1 1 0 3 Braund, Mr. Owen Harris … A/5 21171 7.25 NaN S
2 2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Th… … PC 17599 71.2833 C85 C
3 3 1 3 Heikkinen, Miss. Laina … STON/O2. 3101282 7.925 NaN S
4 4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) … 113803 53.1 C123 S
5 5 0 3 Allen, Mr. William Henry … 373450 8.05 NaN S
6 6 0 3 Moran, Mr. James … 330877 8.4583 NaN Q
7 7 0 1 McCarthy, Mr. Timothy J … 17463 51.8625 E46 S
8 8 0 3 Palsson, Master. Gosta Leonard … 349909 21.075 NaN S
9 9 1 3 Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg) … 347742 11.1333 NaN S
10 10 1 2 Nasser, Mrs. Nicholas (Adele Achem) … 237736 30.0708 NaN C
11 11 1 3 Sandstrom, Miss. Marguerite Rut … PP 9549 16.7 G6 S
12 12 1 1 Bonnell, Miss. Elizabeth … 113783 26.55 C103 S
13 13 0 3 Saundercock, Mr. William Henry … A/5. 2151 8.05 NaN S
14 14 0 3 Andersson, Mr. Anders Johan … 347082 31.275 NaN S
15 15 0 3 Vestrom, Miss. Hulda Amanda Adolfina … 350406 7.8542 NaN S
16 16 1 2 Hewlett, Mrs. (Mary D Kingcome) … 248706 16 NaN S
17 17 0 3 Rice, Master. Eugene … 382652 29.125 NaN Q
18 18 1 2 Williams, Mr. Charles Eugene … 244373 13 NaN S
19 19 0 3 Vander Planke, Mrs. Julius (Emelia Maria Vande… … 345763 18 NaN S
20 20 1 3 Masselmani, Mrs. Fatima … 2649 7.225 NaN C
21 21 0 2 Fynney, Mr. Joseph J … 239865 26 NaN S
22 22 1 2 Beesley, Mr. Lawrence … 248698 13 D56 S
23 23 1 3 McGowan, Miss. Anna “Annie” … 330923 8.0292 NaN Q
24 24 1 1 Sloper, Mr. William Thompson … 113788 35.5 A6 S
25 25 0 3 Palsson, Miss. Torborg Danira … 349909 21.075 NaN S
26 26 1 3 Asplund, Mrs. Carl Oscar (Selma Augusta Emilia… … 347077 31.3875 NaN S
27 27 0 3 Emir, Mr. Farred Chehab … 2631 7.225 NaN C
28 28 0 1 Fortune, Mr. Charles Alexander … 19950 263 C23 C25 C27 S
29 29 1 3 O’Dwyer, Miss. Ellen “Nellie” … 330959 7.8792 NaN Q
… … … … … … … … … …
862 862 0 2 Giles, Mr. Frederick Edward … 28134 11.5 NaN S
863 863 1 1 Swift, Mrs. Frederick Joel (Margaret Welles Ba… … 17466 25.9292 D17 S
864 864 0 3 Sage, Miss. Dorothy Edith “Dolly” … CA. 2343 69.55 NaN S
865 865 0 2 Gill, Mr. John William … 233866 13 NaN S
866 866 1 2 Bystrom, Mrs. (Karolina) … 236852 13 NaN S
867 867 1 2 Duran y More, Miss. Asuncion … SC/PARIS 2149 13.8583 NaN C
868 868 0 1 Roebling, Mr. Washington Augustus II … PC 17590 50.4958 A24 S
869 869 0 3 van Melkebeke, Mr. Philemon … 345777 9.5 NaN S
870 870 1 3 Johnson, Master. Harold Theodor … 347742 11.1333 NaN S
871 871 0 3 Balkic, Mr. Cerin … 349248 7.8958 NaN S
872 872 1 1 Beckwith, Mrs. Richard Leonard (Sallie Monypeny) … 11751 52.5542 D35 S
873 873 0 1 Carlsson, Mr. Frans Olof … 695 5 B51 B53 B55 S
874 874 0 3 Vander Cruyssen, Mr. Victor … 345765 9 NaN S
875 875 1 2 Abelson, Mrs. Samuel (Hannah Wizosky) … P/PP 3381 24 NaN C
876 876 1 3 Najib, Miss. Adele Kiamie “Jane” … 2667 7.225 NaN C
877 877 0 3 Gustafsson, Mr. Alfred Ossian … 7534 9.8458 NaN S
878 878 0 3 Petroff, Mr. Nedelio … 349212 7.8958 NaN S
879 879 0 3 Laleff, Mr. Kristo … 349217 7.8958 NaN S
880 880 1 1 Potter, Mrs. Thomas Jr (Lily Alexenia Wilson) … 11767 83.1583 C50 C
881 881 1 2 Shelley, Mrs. William (Imanita Parrish Hall) … 230433 26 NaN S
882 882 0 3 Markun, Mr. Johann … 349257 7.8958 NaN S
883 883 0 3 Dahlberg, Miss. Gerda Ulrika … 7552 10.5167 NaN S
884 884 0 2 Banfield, Mr. Frederick James … C.A./SOTON 34068 10.5 NaN S
885 885 0 3 Sutehall, Mr. Henry Jr … SOTON/OQ 392076 7.05 NaN S
886 886 0 3 Rice, Mrs. William (Margaret Norton) … 382652 29.125 NaN Q
887 887 0 2 Montvila, Rev. Juozas … 211536 13 NaN S
888 888 1 1 Graham, Miss. Margaret Edith … 112053 30 B42 S
889 889 0 3 Johnston, Miss. Catherine Helen “Carrie” … W./C. 6607 23.45 NaN S
890 890 1 1 Behr, Mr. Karl Howell … 111369 30 C148 C
891 891 0 3 Dooley, Mr. Patrick … 370376 7.75 NaN Q

[892 rows x 12 columns]

In [81]: df_tinct1.groupby(‘性别’)[‘Age’].mean()

KeyError Traceback (most recent call last)
in ()
----> 1 df_tinct1.groupby(‘性别’)[‘Age’].mean()

D:\anaconda\lib\site-packages\pandas\core\base.py in getitem(self, key)
265 else:
266 if key not in self.obj:
–> 267 raise KeyError(“Column not found: {key}”.format(key=key))
268 return self._gotitem(key, ndim=1)
269

KeyError: ‘Column not found: Age’

In [82]: df_tinct1.groupby(‘性别’)[‘年龄’].mean()

DataError Traceback (most recent call last)
in ()
----> 1 df_tinct1.groupby(‘性别’)[‘年龄’].mean()

D:\anaconda\lib\site-packages\pandas\core\groupby\groupby.py in mean(self, *args, **kwargs)
1304 nv.validate_groupby_func(‘mean’, args, kwargs, [‘numeric_only’])
1305 try:
-> 1306 return self._cython_agg_general(‘mean’, **kwargs)
1307 except GroupByError:
1308 raise

D:\anaconda\lib\site-packages\pandas\core\groupby\groupby.py in _cython_agg_general(self, how, alt, numeric_only, min_count)
1054
1055 if len(output) == 0:
-> 1056 raise DataError(‘No numeric types to aggregate’)
1057
1058 return self._wrap_aggregated_output(output, names)

DataError: No numeric types to aggregate

In [83]: df_tinct1.groupby(‘Sex’)[‘Age’].mean()

KeyError Traceback (most recent call last)
in ()
----> 1 df_tinct1.groupby(‘Sex’)[‘Age’].mean()

D:\anaconda\lib\site-packages\pandas\core\generic.py in groupby(self, by, axis, level, as_index, sort, group_keys, squeeze, observed, **kwargs)
6657 return groupby(self, by=by, axis=axis, level=level, as_index=as_index,
6658 sort=sort, group_keys=group_keys, squeeze=squeeze,
-> 6659 observed=observed, **kwargs)
6660
6661 def asfreq(self, freq, method=None, how=None, normalize=False,

D:\anaconda\lib\site-packages\pandas\core\groupby\groupby.py in groupby(obj, by, **kwds)
2150 raise TypeError(‘invalid type: %s’ % type(obj))
2151
-> 2152 return klass(obj, by, **kwds)
2153
2154

D:\anaconda\lib\site-packages\pandas\core\groupby\groupby.py in init(self, obj, keys, axis, level, grouper, exclusions, selection, as_index, sort, group_keys, squeeze, observed, **kwargs)
597 sort=sort,
598 observed=observed,
–> 599 mutated=self.mutated)
600
601 self.obj = obj

D:\anaconda\lib\site-packages\pandas\core\groupby\groupby.py in _get_grouper(obj, key, axis, level, sort, observed, mutated, validate)
3289 in_axis, name, level, gpr = False, None, gpr, None
3290 else:
-> 3291 raise KeyError(gpr)
3292 elif isinstance(gpr, Grouper) and gpr.key is not None:
3293 # Add key to exclusions

KeyError: ‘Sex’

In [84]: df

NameError Traceback (most recent call last)
in ()
----> 1 df

NameError: name ‘df’ is not defined

In [85]: df1
Out[85]:
0 1 2
0 0 1 2
1 3 4 5
2 6 7 8

In [86]: df_tinct1.groupby(‘Sex’)[‘Age’].mean()

KeyError Traceback (most recent call last)
in ()
----> 1 df_tinct1.groupby(‘Sex’)[‘Age’].mean()

D:\anaconda\lib\site-packages\pandas\core\generic.py in groupby(self, by, axis, level, as_index, sort, group_keys, squeeze, observed, **kwargs)
6657 return groupby(self, by=by, axis=axis, level=level, as_index=as_index,
6658 sort=sort, group_keys=group_keys, squeeze=squeeze,
-> 6659 observed=observed, **kwargs)
6660
6661 def asfreq(self, freq, method=None, how=None, normalize=False,

D:\anaconda\lib\site-packages\pandas\core\groupby\groupby.py in groupby(obj, by, **kwds)
2150 raise TypeError(‘invalid type: %s’ % type(obj))
2151
-> 2152 return klass(obj, by, **kwds)
2153
2154

D:\anaconda\lib\site-packages\pandas\core\groupby\groupby.py in init(self, obj, keys, axis, level, grouper, exclusions, selection, as_index, sort, group_keys, squeeze, observed, **kwargs)
597 sort=sort,
598 observed=observed,
–> 599 mutated=self.mutated)
600
601 self.obj = obj

D:\anaconda\lib\site-packages\pandas\core\groupby\groupby.py in _get_grouper(obj, key, axis, level, sort, observed, mutated, validate)
3289 in_axis, name, level, gpr = False, None, gpr, None
3290 else:
-> 3291 raise KeyError(gpr)
3292 elif isinstance(gpr, Grouper) and gpr.key is not None:
3293 # Add key to exclusions

KeyError: ‘Sex’

In [87]: df_tinct1.groupby(‘Sex’)[‘Age’].mean()

KeyError Traceback (most recent call last)
in ()
----> 1 df_tinct1.groupby(‘Sex’)[‘Age’].mean()

D:\anaconda\lib\site-packages\pandas\core\generic.py in groupby(self, by, axis, level, as_index, sort, group_keys, squeeze, observed, **kwargs)
6657 return groupby(self, by=by, axis=axis, level=level, as_index=as_index,
6658 sort=sort, group_keys=group_keys, squeeze=squeeze,
-> 6659 observed=observed, **kwargs)
6660
6661 def asfreq(self, freq, method=None, how=None, normalize=False,

D:\anaconda\lib\site-packages\pandas\core\groupby\groupby.py in groupby(obj, by, **kwds)
2150 raise TypeError(‘invalid type: %s’ % type(obj))
2151
-> 2152 return klass(obj, by, **kwds)
2153
2154

D:\anaconda\lib\site-packages\pandas\core\groupby\groupby.py in init(self, obj, keys, axis, level, grouper, exclusions, selection, as_index, sort, group_keys, squeeze, observed, **kwargs)
597 sort=sort,
598 observed=observed,
–> 599 mutated=self.mutated)
600
601 self.obj = obj

D:\anaconda\lib\site-packages\pandas\core\groupby\groupby.py in _get_grouper(obj, key, axis, level, sort, observed, mutated, validate)
3289 in_axis, name, level, gpr = False, None, gpr, None
3290 else:
-> 3291 raise KeyError(gpr)
3292 elif isinstance(gpr, Grouper) and gpr.key is not None:
3293 # Add key to exclusions

KeyError: ‘Sex’

In [88]: df1
Out[88]:
0 1 2
0 0 1 2
1 3 4 5
2 6 7 8

In [89]: df_tinct1
Out[89]:
乘客ID 是否获救 船舱等级 名字 … 船票 价格 编号 登船地点
0 PassengerId Survived Pclass Name … Ticket Fare Cabin Embarked
1 1 0 3 Braund, Mr. Owen Harris … A/5 21171 7.25 NaN S
2 2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Th… … PC 17599 71.2833 C85 C
3 3 1 3 Heikkinen, Miss. Laina … STON/O2. 3101282 7.925 NaN S
4 4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) … 113803 53.1 C123 S
5 5 0 3 Allen, Mr. William Henry … 373450 8.05 NaN S
6 6 0 3 Moran, Mr. James … 330877 8.4583 NaN Q
7 7 0 1 McCarthy, Mr. Timothy J … 17463 51.8625 E46 S
8 8 0 3 Palsson, Master. Gosta Leonard … 349909 21.075 NaN S
9 9 1 3 Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg) … 347742 11.1333 NaN S
10 10 1 2 Nasser, Mrs. Nicholas (Adele Achem) … 237736 30.0708 NaN C
11 11 1 3 Sandstrom, Miss. Marguerite Rut … PP 9549 16.7 G6 S
12 12 1 1 Bonnell, Miss. Elizabeth … 113783 26.55 C103 S
13 13 0 3 Saundercock, Mr. William Henry … A/5. 2151 8.05 NaN S
14 14 0 3 Andersson, Mr. Anders Johan … 347082 31.275 NaN S
15 15 0 3 Vestrom, Miss. Hulda Amanda Adolfina … 350406 7.8542 NaN S
16 16 1 2 Hewlett, Mrs. (Mary D Kingcome) … 248706 16 NaN S
17 17 0 3 Rice, Master. Eugene … 382652 29.125 NaN Q
18 18 1 2 Williams, Mr. Charles Eugene … 244373 13 NaN S
19 19 0 3 Vander Planke, Mrs. Julius (Emelia Maria Vande… … 345763 18 NaN S
20 20 1 3 Masselmani, Mrs. Fatima … 2649 7.225 NaN C
21 21 0 2 Fynney, Mr. Joseph J … 239865 26 NaN S
22 22 1 2 Beesley, Mr. Lawrence … 248698 13 D56 S
23 23 1 3 McGowan, Miss. Anna “Annie” … 330923 8.0292 NaN Q
24 24 1 1 Sloper, Mr. William Thompson … 113788 35.5 A6 S
25 25 0 3 Palsson, Miss. Torborg Danira … 349909 21.075 NaN S
26 26 1 3 Asplund, Mrs. Carl Oscar (Selma Augusta Emilia… … 347077 31.3875 NaN S
27 27 0 3 Emir, Mr. Farred Chehab … 2631 7.225 NaN C
28 28 0 1 Fortune, Mr. Charles Alexander … 19950 263 C23 C25 C27 S
29 29 1 3 O’Dwyer, Miss. Ellen “Nellie” … 330959 7.8792 NaN Q
… … … … … … … … … …
862 862 0 2 Giles, Mr. Frederick Edward … 28134 11.5 NaN S
863 863 1 1 Swift, Mrs. Frederick Joel (Margaret Welles Ba… … 17466 25.9292 D17 S
864 864 0 3 Sage, Miss. Dorothy Edith “Dolly” … CA. 2343 69.55 NaN S
865 865 0 2 Gill, Mr. John William … 233866 13 NaN S
866 866 1 2 Bystrom, Mrs. (Karolina) … 236852 13 NaN S
867 867 1 2 Duran y More, Miss. Asuncion … SC/PARIS 2149 13.8583 NaN C
868 868 0 1 Roebling, Mr. Washington Augustus II … PC 17590 50.4958 A24 S
869 869 0 3 van Melkebeke, Mr. Philemon … 345777 9.5 NaN S
870 870 1 3 Johnson, Master. Harold Theodor … 347742 11.1333 NaN S
871 871 0 3 Balkic, Mr. Cerin … 349248 7.8958 NaN S
872 872 1 1 Beckwith, Mrs. Richard Leonard (Sallie Monypeny) … 11751 52.5542 D35 S
873 873 0 1 Carlsson, Mr. Frans Olof … 695 5 B51 B53 B55 S
874 874 0 3 Vander Cruyssen, Mr. Victor … 345765 9 NaN S
875 875 1 2 Abelson, Mrs. Samuel (Hannah Wizosky) … P/PP 3381 24 NaN C
876 876 1 3 Najib, Miss. Adele Kiamie “Jane” … 2667 7.225 NaN C
877 877 0 3 Gustafsson, Mr. Alfred Ossian … 7534 9.8458 NaN S
878 878 0 3 Petroff, Mr. Nedelio … 349212 7.8958 NaN S
879 879 0 3 Laleff, Mr. Kristo … 349217 7.8958 NaN S
880 880 1 1 Potter, Mrs. Thomas Jr (Lily Alexenia Wilson) … 11767 83.1583 C50 C
881 881 1 2 Shelley, Mrs. William (Imanita Parrish Hall) … 230433 26 NaN S
882 882 0 3 Markun, Mr. Johann … 349257 7.8958 NaN S
883 883 0 3 Dahlberg, Miss. Gerda Ulrika … 7552 10.5167 NaN S
884 884 0 2 Banfield, Mr. Frederick James … C.A./SOTON 34068 10.5 NaN S
885 885 0 3 Sutehall, Mr. Henry Jr … SOTON/OQ 392076 7.05 NaN S
886 886 0 3 Rice, Mrs. William (Margaret Norton) … 382652 29.125 NaN Q
887 887 0 2 Montvila, Rev. Juozas … 211536 13 NaN S
888 888 1 1 Graham, Miss. Margaret Edith … 112053 30 B42 S
889 889 0 3 Johnston, Miss. Catherine Helen “Carrie” … W./C. 6607 23.45 NaN S
890 890 1 1 Behr, Mr. Karl Howell … 111369 30 C148 C
891 891 0 3 Dooley, Mr. Patrick … 370376 7.75 NaN Q

[892 rows x 12 columns]

In [90]: df_tinct1.groupby(‘性别’)[‘年龄’].mean()

DataError Traceback (most recent call last)
in ()
----> 1 df_tinct1.groupby(‘性别’)[‘年龄’].mean()

D:\anaconda\lib\site-packages\pandas\core\groupby\groupby.py in mean(self, *args, **kwargs)
1304 nv.validate_groupby_func(‘mean’, args, kwargs, [‘numeric_only’])
1305 try:
-> 1306 return self._cython_agg_general(‘mean’, **kwargs)
1307 except GroupByError:
1308 raise

D:\anaconda\lib\site-packages\pandas\core\groupby\groupby.py in _cython_agg_general(self, how, alt, numeric_only, min_count)
1054
1055 if len(output) == 0:
-> 1056 raise DataError(‘No numeric types to aggregate’)
1057
1058 return self._wrap_aggregated_output(output, names)

DataError: No numeric types to aggregate

In [91]: df_tinct1=

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值