pandas学习

这篇博客详细介绍了Pandas库在数据整理中的应用,包括如何创建和加载Series及DataFrame,从CSV、JSON、Excel和数据库加载数据,以及索引和选择数据的方法。还涉及了时间序列数据处理、数据合并、重塑和数据透视表的操作。此外,还涵盖了处理文本数据、缺失数据和提高性能的技巧。
摘要由CSDN通过智能技术生成

Objective : Pandas for Data Wrangling


  1. Introduction to Data Wrangling & Pandas
  2. Series & DataFrames
  3. Loading data into DataFrames
  4. Indexing and selecting data
  5. Working on TimeSeries Data
  6. Merge, join, and concatenate dataframes
  7. Reshaping and pivot tables
  8. Working with text data
  9. Working with missing data
  10. Styling Pandas Table
  11. Computational tools
  12. Group By: split-apply-combine
  13. Options and settings
  14. Enhancing performance
  15. 介绍数据纠缠和Pandas
  16. 系列和数据框
  17. 将数据加载到DataFrames中
  18. 索引编制和选择数据
  19. 关于时间序列数据的工作
    1. 合并、连接和串联数据框。
  20. 重组和数据透视表
  21. 处理文本数据
  22. 处理缺失数据的工作
  23. pandas的样式
  24. 计算工具
  25. 分组由。split-apply-combine
  26. 选项和设置
  27. 提高性能

Introduction to Data Wrangling & Pandas


Data Wrangling

  • Getting & Reading data from different sources.
  • Cleaning Data
  • Shaping & Structuring Data
  • Storing Data

There are many tools & libraries available for data wrangling. Tools like rapidminer & libraries like pandas. Organizations find libraries more suited because of flexibility.
#####数据整理

  • 从不同来源获取和读取数据。
  • 清理数据
  • 塑造和结构化数据
  • 储存数据

有许多工具和库可以用于数据整理。像 rapidminer 和 pandas 这样的工具和库。组织觉得库更适合,因为它的灵活性。

Pandas

  • High Performance, Easy-to-use open source library for Data Analysis
  • Creates tabular format of data from different sources like csv, json, database.
  • Have utilities for descriptive statistics, aggregation, handling missing data
  • Database utilities like merge, join are available
  • Fast, Programmable & Easy alternative to spreadsheets
  • 高性能、易于使用的开源数据分析库
  • 创建不同来源的数据的表格格式,如csv、json、数据库。
  • 具有描述性统计、聚合、处理缺失数据的实用工具。
  • 可使用数据库工具,如合并、加入等。
  • 快速、可编程和简单的电子表格的替代方案。

2. Series & DataFrames

import pandas as pd
import numpy as np

pd.__version__
'0.25.1'
Series
  • Series datastructure represents a column.
  • Each columns will a data type
  • Combine multiple columns to create a table ( .i.e DataFrame )
  • 系列数据结构代表一个列。
  • 每个列将有一个数据类型
  • 组合多个列来创建一个表(即DataFrame)。
ser1 = pd.Series(data=[1,2,3,4,5], index=list('abcde'))
ser1
a    1
b    2
c    3
d    4
e    5
dtype: int64
ser1.dtype
dtype('int64')
ser2 = pd.Series(data=[11,22,33,44,55], index=list('abcde'))
ser2
a    11
b    22
c    33
d    44
e    55
dtype: int64
DataFrame
  • DataFrame is tabular representation of data.
  • Combine multiple series to create a dataframe
  • Data corresponding to same index belongs to same row
  • DataFrame是数据的表格化表示。
  • 结合多个系列来创建一个数据框架。
  • 同一索引对应的数据属于同一行。
df = pd.DataFrame({
   'A':ser1, 'B':ser2})
df
A B
a 1 11
b 2 22
c 3 33
d 4 44
e 5 55
df = pd.DataFrame(data=np.random.randint(1,10,size=(10,10)), 
             index=list('ABCDEFGHIJ'), 
             columns=list('abcdefghij'))
df
a b c d e f g h i j
A 3 3 4 1 1 9 3 1 2 3
B 7 6 4 6 5 2 7 3 8 6
C 1 5 5 1 6 5 3 8 9 6
D 4 7 7 2 9 7 5 8 5 1
E 1 4 5 9 8 4 7 2 6 9
F 6 2 8 3 7 5 2 3 5 8
G 6 8 4 9 3 2 1 3 7 9
H 9 5 3 1 7 8 2 6 6 3
I 9 8 6 9 4 6 3 3 7 6
J 4 8 1 4 3 3 9 9 7 8

Objective : Loading Data into DataFrames|目标:将数据加载到DataFrames中


  1. Sources from which dataframes can be created
  2. Loading from CSV
  3. Loading from JSON - Structured & Unstructured
  4. Loading from Excel
  5. Creating pickled data & Loading from Pickled Data
  6. Loading from Database

  1. 可据此创建数据框的来源
  2. 从CSV加载
  3. 从JSON加载–结构化和非结构化
  4. 从Excel加载
  5. 创建腌制数据和从腌制数据中加载数据
  6. 从数据库加载

Sources from which dataframes can be created|可以创建数据框的来源

  • Reading data from different sources, here is the list.
  • Also, includes writing data to different sources.
  • 读取不同来源的数据,这里是列表。
  • 还包括向不同来源写入数据。

Reading CSV

import pandas as pd
rental_data = pd.read_csv('../Data/house_rental_data.csv.txt')
rental_data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 645 entries, 0 to 644
Data columns (total 8 columns):
Unnamed: 0     645 non-null int64
Sqft           645 non-null float64
Floor          645 non-null int64
TotalFloor     645 non-null int64
Bedroom        645 non-null int64
Living.Room    645 non-null int64
Bathroom       645 non-null int64
Price          645 non-null int64
dtypes: float64(1), int64(7)
memory usage: 40.4 KB
rental_data.head()
Unnamed: 0 Sqft Floor TotalFloor Bedroom Living.Room Bathroom Price
0 1 1177.698 2 7 2 2 2 62000
1 2 2134.800 5 7 4 2 2 78000
2 3 1138.560 5 7 2 2 1 58000
3 4 1458.780 2 7 3 2 2 45000
4 5 967.776 11 14 3 2 2 45000
rental_data = pd.read_csv('../Data/house_rental_data.csv.txt', index_col = 'Unnamed: 0')
rental_data.head()
Sqft Floor TotalFloor Bedroom Living.Room Bathroom Price
1 1177.698 2 7 2 2 2 62000
2 2134.800 5 7 4 2 2 78000
3 1138.560 5 7 2 2 1 58000
4 1458.780 2 7 3 2 2 45000
5 967.776 11 14 3 2 2 45000
rental_data = pd.read_csv('../Data/house_rental_data.csv.txt', usecols=lambda c: c.startswith('B'))
rental_data.head()
Bedroom Bathroom
0 2 2
1 4 2
2 2 1
3 3 2
4 3 2
#help(pd.read_csv)
'''
nrows : int, 可选
        要读取的文件行数。用于读取大文件的碎片。
'''
rental_data = pd.read_csv('../Data/house_rental_data.csv.txt', nrows=10)
rental_data.shape
(10, 8)
help(pd.read_csv)
Help on function read_csv in module pandas.io.parsers:

read_csv(filepath_or_buffer: Union[str, pathlib.Path, IO[~AnyStr]], sep=',', delimiter=None, header='infer', names=None, index_col=None, usecols=None, squeeze=False, prefix=None, mangle_dupe_cols=True, dtype=None, engine=None, converters=None, true_values=None, false_values=None, skipinitialspace=False, skiprows=None, skipfooter=0, nrows=None, na_values=None, keep_default_na=True, na_filter=True, verbose=False, skip_blank_lines=True, parse_dates=False, infer_datetime_format=False, keep_date_col=False, date_parser=None, dayfirst=False, cache_dates=True, iterator=False, chunksize=None, compression='infer', thousands=None, decimal=b'.', lineterminator=None, quotechar='"', quoting=0, doublequote=True, escapechar=None, comment=None, encoding=None, dialect=None, error_bad_lines=True, warn_bad_lines=True, delim_whitespace=False, low_memory=True, memory_map=False, float_precision=None)
    Read a comma-separated values (csv) file into DataFrame.
    
    Also supports optionally iterating or breaking of the file
    into chunks.
    
    Additional help can be found in the online docs for
    `IO Tools <http://pandas.pydata.org/pandas-docs/stable/user_guide/io.html>`_.
    
    Parameters
    ----------
    filepath_or_buffer : str, path object or file-like object
        Any valid string path is acceptable. The string could be a URL. Valid
        URL schemes include http, ftp, s3, and file. For file URLs, a host is
        expected. A local file could be: file://localhost/path/to/table.csv.
    
        If you want to pass in a path object, pandas accepts any ``os.PathLike``.
    
        By file-like object, we refer to objects with a ``read()`` method, such as
        a file handler (e.g. via builtin ``open`` function) or ``StringIO``.
    sep : str, default ','
        Delimiter to use. If sep is None, the C engine cannot automatically detect
        the separator, but the Python parsing engine can, meaning the latter will
        be used and automatically detect the separator by Python's builtin sniffer
        tool, ``csv.Sniffer``. In addition, separators longer than 1 character and
        different from ``'\s+'`` will be interpreted as regular expressions and
        will also force the use of the Python parsing engine. Note that regex
        delimiters are prone to ignoring quoted data. Regex example: ``'\r\t'``.
    delimiter : str, default ``None``
        Alias for sep.
    header : int, list of int, default 'infer'
        Row number(s) to use as the column names, and the start of the
        data.  Default behavior is to infer the column names: if no names
        are passed the behavior is identical to ``header=0`` and column
        names are inferred from the first line of the file, if column
        names are passed explicitly then the behavior is identical to
        ``header=None``. Explicitly pass ``header=0`` to be able to
        replace existing names. The header can be a list of integers that
        specify row locations for a multi-index on the columns
        e.g. [0,1,3]. Intervening rows that are not specified will be
        skipped (e.g. 2 in this example is skipped). Note that this
        parameter ignores commented lines and empty lines if
        ``skip_blank_lines=True``, so ``header=0`` denotes the first line of
        data rather than the first line of the file.
    names : array-like, optional
        List of column names to use. If file contains no header row, then you
        should explicitly pass ``header=None``. Duplicates in this list are not
        allowed.
    index_col : int, str, sequence of int / str, or False, default ``None``
      Column(s) to use as the row labels of the ``DataFrame``, either given as
      string name or column index. If a sequence of int / str is given, a
      MultiIndex is used.
    
      Note: ``index_col=False`` can be used to force pandas to *not* use the first
      column as the index, e.g. when you have a malformed file with delimiters at
      the end of each line.
    usecols : list-like or callable, optional
        Return a subset of the columns. If list-like, all elements must either
        be positional (i.e. integer indices into the document columns) or strings
        that correspond to column names provided either by the user in `names` or
        inferred from the document header row(s). For example, a valid list-like
        `usecols` parameter would be ``[0, 1, 2]`` or ``['foo', 'bar', 'baz']``.
        Element order is ignored, so ``usecols=[0, 1]`` is the same as ``[1, 0]``.
        To instantiate a DataFrame from ``data`` with element order preserved use
        ``pd.read_csv(data, usecols=['foo', 'bar'])[['foo', 'bar']]`` for columns
        in ``['foo', 'bar']`` order or
        ``pd.read_csv(data, usecols=['foo', 'bar'])[['bar', 'foo']]``
        for ``['bar', 'foo']`` order.
    
        If callable, the callable function will be evaluated against the column
        names, returning names where the callable function evaluates to True. An
        example of a valid callable argument would be ``lambda x: x.upper() in
        ['AAA', 'BBB', 'DDD']``. Using this parameter results in much faster
        parsing time and lower memory usage.
    squeeze : bool, default False
        If the parsed data only contains one column then return a Series.
    prefix : str, optional
        Prefix to add to column numbers when no header, e.g. 'X' for X0, X1, ...
    mangle_dupe_cols : bool, default True
        Duplicate columns will be specified as 'X', 'X.1', ...'X.N', rather than
        'X'...'X'. Passing in False will cause data to be overwritten if there
        are duplicate names in the columns.
    dtype : Type name or dict of column -> type, optional
        Data type for data or columns. E.g. {'a': np.float64, 'b': np.int32,
        'c': 'Int64'}
        Use `str` or `object` together with suitable `na_values` settings
        to preserve and not interpret dtype.
        If converters are specified, they will be applied INSTEAD
        of dtype conversion.
    engine : {'c', 'python'}, optional
        Parser engine to use. The C engine is faster while the python engine is
        currently more feature-complete.
    converters : dict, optional
        Dict of functions for converting values in certain columns. Keys can either
        be integers or column labels.
    true_values : list, optional
        Values to consider as True.
    false_values : list, optional
        Values to consider as False.
    skipinitialspace : bool, default False
        Skip spaces after delimiter.
    skiprows : list-like, int or callable, optional
        Line numbers to skip (0-indexed) or number of lines to skip (int)
        at the start of the file.
    
        If callable, the callable function will be evaluated against the row
        indices, returning True if the row should be skipped and False otherwise.
        An example of a valid callable argument would be ``lambda x: x in [0, 2]``.
    skipfooter : int, default 0
        Number of lines at bottom of file to skip (Unsupported with engine='c').
    nrows : int, optional
        Number of rows of file to read. Useful for reading pieces of large files.
    na_values : scalar, str, list-like, or dict, optional
        Additional strings to recognize as NA/NaN. If dict passed, specific
        per-column NA values.  By default the following values are interpreted as
        NaN: '', '#N/A', '#N/A N/A', '#NA', '-1.#IND', '-1.#QNAN', '-NaN', '-nan',
        '1.#IND', '1.#QNAN', 'N/A', 'NA', 'NULL', 'NaN', 'n/a', 'nan',
        'null'.
    keep_default_na : bool, default True
        Whether or not to include the default NaN values when parsing the data.
        Depending on whether `na_values` is passed in, the behavior is as follows:
    
        * If `keep_default_na` is True, and `na_values` are specified, `na_values`
          is appended to the default NaN values used for parsing.
        * If `keep_default_na` is True, and `na_values` are not specified, only
          the default NaN values are used for parsing.
        * If `keep_default_na` is False, and `na_values` are specified, only
          the NaN values specified `na_values` are used for parsing.
        * If `keep_default_na` is False, and `na_values` are not specified, no
          strings will be parsed as NaN.
    
        Note that if `na_filter` is passed in as False, the `keep_default_na` and
        `na_values` parameters will be ignored.
    na_filter : bool, default True
        Detect missing value markers (empty strings and the value of na_values). In
        data without any NAs, passing na_filter=False can improve the performance
        of reading a large file.
    verbose : bool, default False
        Indicate number of NA values placed in non-numeric columns.
    skip_blank_lines : bool, default True
        If True, skip over blank lines rather than interpreting as NaN values.
    parse_dates : bool or list of int or names or list of lists or dict, default False
        The behavior is as follows:
    
        * boolean. If True -> try parsing the index.
        * list of int or names. e.g. If [1, 2, 3] -> try parsing columns 1, 2, 3
          each as a separate date column.
        * list of lists. e.g.  If [[1, 3]] -> combine columns 1 and 3 and parse as
          a single date column.
        * dict, e.g. {'foo' : [1, 3]} -> parse columns 1, 3 as date and call
          result 'foo'
    
        If a column or index cannot be represented as an array of datetimes,
        say because of an unparseable value or a mixture of timezones, the column
        or index will be returned unaltered as an object data type. For
        non-standard datetime parsing, use ``pd.to_datetime`` after
        ``pd.read_csv``. To parse an index or column with a mixture of timezones,
        specify ``date_parser`` to be a partially-applied
        :func:`pandas.to_datetime` with ``utc=True``. See
        :ref:`io.csv.mixed_timezones` for more.
    
        Note: A fast-path exists for iso8601-formatted dates.
    infer_datetime_format : bool, default False
        If True and `parse_dates` is enabled, pandas will attempt to infer the
        format of the datetime strings in the columns, and if it can be inferred,
        switch to a faster method of parsing them. In some cases this can increase
        the parsing speed by 5-10x.
    keep_date_col : bool, default False
        If True and `parse_dates` specifies combining multiple columns then
        keep the original columns.
    date_parser : function, optional
        Function to use for converting a sequence of string columns to an array of
        datetime instances. The default uses ``dateutil.parser.parser`` to do the
        conversion. Pandas will try to call `date_parser` in three different ways,
        advancing to the next if an exception occurs: 1) Pass one or more arrays
        (as defined by `parse_dates`) as arguments; 2) concatenate (row-wise) the
        string values from the columns defined by `parse_dates` into a single array
        and pass that; and 3) call `date_parser` once for each row using one or
        more strings (corresponding to the columns defined by `parse_dates`) as
        arguments.
    dayfirst : bool, default False
        DD/MM format dates, international and European format.
    cache_dates : boolean, default True
        If True, use a cache of unique, converted dates to apply the datetime
        conversion. May produce significant speed-up when parsing duplicate
        date strings, especially ones with timezone offsets.
    
        .. versionadded:: 0.25.0
    iterator : bool, default False
        Return TextFileReader object for iteration or getting chunks with
        ``get_chunk()``.
    chunksize : int, optional
        Return TextFileReader object for iteration.
        See the `IO Tools docs
        <http://pandas.pydata.org/pandas-docs/stable/io.html#io-chunking>`_
        for more information on ``iterator`` and ``chunksize``.
    compression : {'infer', 'gzip', 'bz2', 'zip', 'xz', None}, default 'infer'
        For on-the-fly decompression of on-disk data. If 'infer' and
        `filepath_or_buffer` is path-like, then detect compression from the
        following extensions: '.gz', '.bz2', '.zip', or '.xz' (otherwise no
        decompression). If using 'zip', the ZIP file must contain only one data
        file to be read in. Set to None for no decompression.
    
        .. versionadded:: 0.18.1 support for 'zip' and 'xz' compression.
    
    thousands : str, optional
        Thousands separator.
    decimal : str, default '.'
        Character to recognize as decimal point (e.g. use ',' for European data).
    lineterminator : str (length 1), optional
        Character to break file into lines. Only valid with C parser.
    quotechar : str (length 1), optional
        The character used to denote the start and end of a quoted item. Quoted
        items can include the delimiter and it will be ignored.
    quoting : int or csv.QUOTE_* instance, default 0
        Control field quoting behavior per ``csv.QUOTE_*`` constants. Use one of
        QUOTE_MINIMAL (0), QUOTE_ALL (1), QUOTE_NONNUMERIC (2) or QUOTE_NONE (3).
    doublequote : bool, default ``True``
       When quotechar is specified and quoting is not ``QUOTE_NONE``, indicate
       whether or not to interpret two consecutive quotechar elements INSIDE a
       field as a single ``quotechar`` element.
    escapechar : str (length 1), optional
        One-character string used to escape other characters.
    comment : str, optional
        Indicates remainder of line should not be parsed. If found at the beginning
        of a line, the line will be ignored altogether. This parameter must be a
        single character. Like empty lines (as long as ``skip_blank_lines=True``),
        fully commented lines are ignored by the parameter `header` but not by
        `skiprows`. For example, if ``comment='#'``, parsing
        ``#empty\na,b,c\n1,2,3`` with ``header=0`` will result in 'a,b,c' being
        treated as the header.
    encoding : str, optional
        Encoding to use for UTF when reading/writing (ex. 'utf-8'). `List of Python
        standard encodings
        <https://docs.python.org/3/library/codecs.html#standard-encodings>`_ .
    dialect : str or csv.Dialect, optional
        If provided, this parameter will override values (default or not) for the
        following parameters: `delimiter`, `doublequote`, `escapechar`,
        `skipinitialspace`, `quotechar`, and `quoting`. If it is necessary to
        override values, a ParserWarning will be issued. See csv.Dialect
        documentation for more details.
    error_bad_lines : bool, default True
        Lines with too many fields (e.g. a csv line with too many commas) will by
        default cause an exception to be raised, and no DataFrame will be returned.
        If False, then these "bad lines" will dropped from the DataFrame that is
        returned.
    warn_bad_lines : bool, default True
        If error_bad_lines is False, and warn_bad_lines is True, a warning for each
        "bad line" will be output.
    delim_whitespace : bool, default False
        Specifies whether or not whitespace (e.g. ``' '`` or ``'    '``) will be
        used as the sep. Equivalent to setting ``sep='\s+'``. If this option
        is set to True, nothing should be passed in for the ``delimiter``
        parameter.
    
        .. versionadded:: 0.18.1 support for the Python parser.
    
    low_memory : bool, default True
        Internally process the file in chunks, resulting in lower memory use
        while parsing, but possibly mixed type inference.  To ensure no mixed
        types either set False, or specify the type with the `dtype` parameter.
        Note that the entire file is read into a single DataFrame regardless,
        use the `chunksize` or `iterator` parameter to return the data in chunks.
        (Only valid with C parser).
    memory_map : bool, default False
        If a filepath is provided for `filepath_or_buffer`, map the file object
        directly onto memory and access the data directly from there. Using this
        option can improve performance because there is no longer any I/O overhead.
    float_precision : str, optional
        Specifies which converter the C engine should use for floating-point
        values. The options are `None` for the ordinary converter,
        `high` for the high-precision converter, and `round_trip` for the
        round-trip converter.
    
    Returns
    -------
    DataFrame or TextParser
        A comma-separated values (csv) file is returned as two-dimensional
        data structure with labeled axes.
    
    See Also
    --------
    to_csv : Write DataFrame to a comma-separated values (csv) file.
    read_csv : Read a comma-separated values (csv) file into DataFrame.
    read_fwf : Read a table of fixed-width formatted lines into DataFrame.
    
    Examples
    --------
    >>> pd.read_csv('data.csv')  # doctest: +SKIP
'''
 chunksize : int, 可选
        返回TextFileReader对象进行迭代。
        请参见 `IO工具文档
        <http://pandas.pydata.org/pandas-docs/stable/io.html#io-chunking>`http://pandas.pydata.org/pandas-docs/stable/io.html#io-chunking
        关于 "iterator "和 "chunksize "的更多信息。
'''
rental_data_itr = pd.read_csv('../Data/house_rental_data.csv.txt', chunksize=300)
for data in rental_data_itr:
    print (data.count())
Unnamed: 0     300
Sqft           300
Floor          300
TotalFloor     300
Bedroom        300
Living.Room    300
Bathroom       300
Price          300
dtype: int64
Unnamed: 0     300
Sqft           300
Floor          300
TotalFloor     300
Bedroom        300
Living.Room    300
Bathroom       300
Price          300
dtype: int64
Unnamed: 0     45
Sqft           45
Floor          45
TotalFloor     45
Bedroom        45
Living.Room    45
Bathroom       45
Price          45
dtype: int64
titanic_data = pd.read_csv('../Data/titanic-train.csv.txt', index_col = 'PassengerId', na_values={
   'Ticket':'PC 17599'})
titanic_data.head()
Survived Pclass Name Sex Age SibSp Parch Ticket Fare Cabin Embarked
PassengerId
1 0 3 Braund, Mr. Owen Harris male 22.0 1 0 A/5 21171 7.2500 NaN S
2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1 0 NaN 71.2833 C85 C
3 1 3 Heikkinen, Miss. Laina female 26.0 0 0 STON/O2. 3101282 7.9250 NaN S
4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 0 113803 53.1000 C123 S
5 0 3 Allen, Mr. William Henry male 35.0 0 0 373450 8.0500 NaN S
pd.read_csv('../Data/sales-data.csv').head()
Month Sales
0 1-01 266.0
1 1-02 145.9
2 1-03 183.1
3 1-04 119.3
4 1-05 180.3
from datetime import datetime

def parser(x):
    return datetime.strptime('200'+x, '%Y-%m')
 
data = pd.read_csv('../Data/sales-data.csv', header=0, parse_dates=[0], index_col=0, date_parser=parser)
data.head()
Sales
Month
2001-01-01 266.0
2001-02-01 145.9
2001-03-01 183.1
2001-04-01 119.3
2001-05-01 180.3

Loading from JSON

pd.read_json('https://raw.githubusercontent.com/corysimmons/colors.json/master/colors.json', orient='records').T.head()
0 1 2 3
aliceblue 240 248 255 1
antiquewhite 250 235 215 1
aqua 0 255 255 1
aquamarine 127 255 212 1
azure 240 255 255 1
pd.set_option('display.max_colwidth', -1)
pd.read_json('../Data/raw_nyc_phil.json').head(1)
programs
0 {'season': '1842-43', 'orchestra': 'New York Philharmonic', 'concerts': [{'Date': '1842-12-07T05:00:00Z', 'eventType': 'Subscription Season', 'Venue': 'Apollo Rooms', 'Location': 'Manhattan, NY', 'Time': '8:00PM'}], 'programID': '3853', 'works': [{'workTitle': 'SYMPHONY NO. 5 IN C MINOR, OP.67', 'conductorName': 'Hill, Ureli Corelli', 'ID': '52446*', 'soloists': [], 'composerName': 'Beethoven, Ludwig van'}, {'workTitle': 'OBERON', 'composerName': 'Weber, Carl Maria Von', 'conductorName': 'Timm, Henry C.', 'ID': '8834*4', 'soloists': [{'soloistName': 'Otto, Antoinette', 'soloistRoles': 'S', 'soloistInstrument': 'Soprano'}], 'movement': '"Ozean, du Ungeheuer" (Ocean, thou mighty monster), Reiza (Scene and Aria), Act II'}, {'workTitle': 'QUINTET, PIANO, D MINOR, OP. 74', 'ID': '3642*', 'soloists': [{'soloistName': 'Scharfenberg, William', 'soloistRoles': 'A', 'soloistInstrument': 'Piano'}, {'soloistName': 'Hill, Ureli Corelli', 'soloistRoles': 'A', 'soloistInstrument': 'Violin'}, {'soloistName': 'Derwort, G. H.', 'soloistRoles': 'A', 'soloistInstrument': 'Viola'}, {'soloistName': 'Boucher, Alfred', 'soloistRoles': 'A', 'soloistInstrument': 'Cello'}, {'soloistName': 'Rosier, F. W.', 'soloistRoles': 'A', 'soloistInstrument': 'Contrabass'}], 'composerName': 'Hummel, Johann'}, {'interval': 'Intermission', 'ID': '0*', 'soloists': []}, {'workTitle': 'OBERON', 'composerName': 'Weber, Carl Maria Von', 'conductorName': 'Etienne, Denis G.', 'ID': '8834*3', 'soloists': [], 'movement': 'Overture'}, {'workTitle': 'ARMIDA', 'composerName': 'Rossini, Gioachino', 'conductorName': 'Timm, Henry C.', 'ID': '8835*1', 'soloists': [{'soloistName': 'Otto, Antoinette', 'soloistRoles': 'S', 'soloistInstrument': 'Soprano'}, {'soloistName': 'Horn, Charles Edward', 'soloistRoles': 'S', 'soloistInstrument': 'Tenor'}], 'movement': 'Duet'}, {'workTitle': 'FIDELIO, OP. 72', 'composerName': 'Beethoven, Ludwig van', 'conductorName': 'Timm, Henry C.', 'ID': '8837*6', 'soloists': [{'soloistName': 'Horn, Charles Edward', 'soloistRoles': 'S', 'soloistInstrument': 'Tenor'}], 'movement': '"In Des Lebens Fruhlingstagen...O spur ich nicht linde," Florestan (aria)'}, {'workTitle': 'ABDUCTION FROM THE SERAGLIO,THE, K.384', 'composerName': 'Mozart, Wolfgang Amadeus', 'conductorName': 'Timm, Henry C.', 'ID': '8336*4', 'soloists': [{'soloistName': 'Otto, Antoinette', 'soloistRoles': 'S', 'soloistInstrument': 'Soprano'}], 'movement': '"Ach Ich liebte," Konstanze (aria)'}, {'workTitle': 'OVERTURE NO. 1, D MINOR, OP. 38', 'conductorName': 'Timm, Henry C.', 'ID': '5543*', 'soloists': [], 'composerName': 'Kalliwoda, Johann W.'}], 'id': '38e072a7-8fc9-4f9a-8eac-3957905c0002'}
import json
with open('../Data/raw_nyc_phil.json') as f:
    d = json.load(f)
nycphil = pd.io.json.json_normalize(d['programs'])
nycphil.head(3)
season orchestra concerts programID works id
0 1842-43 New York Philharmonic [{'Date': '1842-12-07T05:00:00Z', 'eventType': 'Subscription Season', 'Venue': 'Apollo Rooms', 'Location': 'Manhattan, NY', 'Time': '8:00PM'}] 3853 [{'workTitle': 'SYMPHONY NO. 5 IN C MINOR, OP.67', 'conductorName': 'Hill, Ureli Corelli', 'ID': '52446*', 'soloists': [], 'composerName': 'Beethoven, Ludwig van'}, {'workTitle': 'OBERON', 'composerName': 'Weber, Carl Maria Von', 'conductorName': 'Timm, Henry C.', 'ID': '8834*4', 'soloists': [{'soloistName': 'Otto, Antoinette', 'soloistRoles': 'S', 'soloistInstrument': 'Soprano'}], 'movement': '"Ozean, du Ungeheuer" (Ocean, thou mighty monster), Reiza (Scene and Aria), Act II'}, {'workTitle': 'QUINTET, PIANO, D MINOR, OP. 74', 'ID': '3642*', 'soloists': [{'soloistName': 'Scharfenberg, William', 'soloistRoles': 'A', 'soloistInstrument': 'Piano'}, {'soloistName': 'Hill, Ureli Corelli', 'soloistRoles': 'A', 'soloistInstrument': 'Violin'}, {'soloistName': 'Derwort, G. H.', 'soloistRoles': 'A', 'soloistInstrument': 'Viola'}, {'soloistName': 'Boucher, Alfred', 'soloistRoles': 'A', 'soloistInstrument': 'Cello'}, {'soloistName': 'Rosier, F. W.', 'soloistRoles': 'A', 'soloistInstrument': 'Contrabass'}], 'composerName': 'Hummel, Johann'}, {'interval': 'Intermission', 'ID': '0*', 'soloists': []}, {'workTitle': 'OBERON', 'composerName': 'Weber, Carl Maria Von', 'conductorName': 'Etienne, Denis G.', 'ID': '8834*3', 'soloists': [], 'movement': 'Overture'}, {'workTitle': 'ARMIDA', 'composerName': 'Rossini, Gioachino', 'conductorName': 'Timm, Henry C.', 'ID': '8835*1', 'soloists': [{'soloistName': 'Otto, Antoinette', 'soloistRoles': 'S', 'soloistInstrument': 'Soprano'}, {'soloistName': 'Horn, Charles Edward', 'soloistRoles': 'S', 'soloistInstrument': 'Tenor'}], 'movement': 'Duet'}, {'workTitle': 'FIDELIO, OP. 72', 'composerName': 'Beethoven, Ludwig van', 'conductorName': 'Timm, Henry C.', 'ID': '8837*6', 'soloists': [{'soloistName': 'Horn, Charles Edward', 'soloistRoles': 'S', 'soloistInstrument': 'Tenor'}], 'movement': '"In Des Lebens Fruhlingstagen...O spur ich nicht linde," Florestan (aria)'}, {'workTitle': 'ABDUCTION FROM THE SERAGLIO,THE, K.384', 'composerName': 'Mozart, Wolfgang Amadeus', 'conductorName': 'Timm, Henry C.', 'ID': '8336*4', 'soloists': [{'soloistName': 'Otto, Antoinette', 'soloistRoles': 'S', 'soloistInstrument': 'Soprano'}], 'movement': '"Ach Ich liebte," Konstanze (aria)'}, {'workTitle': 'OVERTURE NO. 1, D MINOR, OP. 38', 'conductorName': 'Timm, Henry C.', 'ID': '5543*', 'soloists': [], 'composerName': 'Kalliwoda, Johann W.'}] 38e072a7-8fc9-4f9a-8eac-3957905c0002
1 1842-43 New York Philharmonic [{'Date': '1843-02-18T05:00:00Z', 'eventType': 'Subscription Season', 'Venue': 'Apollo Rooms', 'Location': 'Manhattan, NY', 'Time': '8:00PM'}] 5178 [{'workTitle': 'SYMPHONY NO. 3 IN E FLAT MAJOR, OP. 55 (EROICA)', 'conductorName': 'Hill, Ureli Corelli', 'ID': '52437*', 'soloists': [], 'composerName': 'Beethoven, Ludwig van'}, {'workTitle': 'I PURITANI', 'composerName': 'Bellini, Vincenzo', 'conductorName': 'Hill, Ureli Corelli', 'ID': '8838*2', 'soloists': [{'soloistName': 'Otto, Antoinette', 'soloistRoles': 'S', 'soloistInstrument': 'Soprano'}], 'movement': 'Elvira (aria): "Qui la voce...Vien, diletto"'}, {'workTitle': 'CELEBRATED ELEGIE', 'conductorName': 'Hill, Ureli Corelli', 'ID': '3659*', 'soloists': [{'soloistName': 'Boucher, Alfred', 'soloistRoles': 'S', 'soloistInstrument': 'Cello'}], 'composerName': 'Romberg, Bernhard'}, {'interval': 'Intermission', 'ID': '0*', 'soloists': []}, {'workTitle': 'WILLIAM TELL', 'composerName': 'Rossini, Gioachino', 'conductorName': 'Alpers, William', 'ID': '8839*2', 'soloists': [], 'movement': 'Overture'}, {'workTitle': 'STABAT MATER', 'composerName': 'Rossini, Gioachino', 'conductorName': 'Alpers, William', 'ID': '53076*2', 'soloists': [{'soloistName': 'Otto, Antoinette', 'soloistRoles': 'S', 'soloistInstrument': 'Soprano'}], 'movement': 'Inflammatus et Accensus (Aria with Chorus)'}, {'workTitle'
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

a useful man

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值