On the python third-party libraries --pandas (b)

pandas use Tips

1 Create DataFrame by Series

Pandas mentioned in the series in the first post, Series DataFrame be seen as a special case, that is only one data. That being the case, is it possible to form a parallel multiple Series DataFrame it? Of course, in this way creating DataFrame also referred to establish a data dictionary, each column acts as a key column name dictionary, Series configured to act as the column data corresponding to the key value. Examples are as follows:

Figure above, Series Type act df_1 second column, as pandas default to "0,1,2,3" to the ranks of the form name, in this embodiment, the dictionary is the column name of the key, the default names automatically generated row, and for name corresponds to an existing line, when you create a second column specifies the Series line name index = list (range (4) ).
Further, one-dimensional array numpy may also function to act as DataFrame a column of data, only if a value assigned to a column, the pandas will automatically repeat the value according to the number of lines to complement the column.

2 View DataFrame common attributes

NOTE: The following example is a demonstration of the new df_2 the same way to create a dictionary in the previous section, but slightly larger amount of data.

2.1 Check the columns of data types

2.2 view names and ranks of specific data

Values ​​obtained using the method of direct and multi-dimensional array form in numpy same data type.

2.3 View Data Description

Data statistics describe just gives some columns for numeric data.
For some permutation, a sort operation pandas, these methods and numpy Method no different, is not repeated herein.

Select Data setting condition 3

The previous blog post mentioned the ranks of selected data with names, ranks and position of both hybrid approach, in fact, there is a condition by selecting the data for a given method.

Figure above, the condition setting value greater than zero to select column A, and then extracted to form a new DataFrame its line.
Of course, the conditions may be set simultaneously, and to specify the selected row.

This issue is over, the back will continue to introduce common operations of pandas.

Guess you like

Origin www.cnblogs.com/pythonfl/p/12276007.html