Python pands and matplotlib common commands

A, pandas commonly used functions

df.sort_values () - sort data by ranks
df.sort_index () - sorted by ranks tag
df.duplicated () - Analyzing duplicate data
df.drop_duplicates () - de-emphasis
df.reset_index () - Reset index
df.set_index () - the index of a column to
df.rename (columns = {}) - modify Listing
df = df [~ df [] == XX] - "~" is negated
series. isin (list) - series in the list if a single data
series.str.replace ( '', '') - series character substitution
series.str.contains ( 'xx') - series whether to include "xx" character , "XX" can be "^ [92]" or [0-9]
df.apply (FUNC) - application of custom functions, underlayer C operation speed
df.apply (lambda x: x.sum () ) - anonymous function
df.empty - df is empty
df.fillna ( '') - filling missing values
df.loc [xx,:] - remove all the data of a row
pd.concat () - df splicing
df.head (n) - the first n rows show
df.T - df transpose
df.corr () - calculate the correlation coefficient
df.to_csv (file,encoding =) - Save the file
pd.read_csv(file, index_col=,encoding=)——读取文件
pd.read_excel(file, sheet_name, index_col,encoding)

pandas中excel操作
writer = pd.ExcelWriter(filePath)
df.to_excel(writer,sheet_name=, encoding=)
writer.save()

Two, matplotlib common operations

plt.rcParams [ 'font.sans-serif'] = [ 'SimHei'] # tab to normal display Chinese
plt.rcParams [ 'axes.unicode_minus'] = False # minus sign to the normal display
plt.rcParams [' figure .figsize '] = (16, 9 ) # resolution of 16:. 9
plt.cla () - clear the original image
plt.grid (b = None, which = ' major ', axis =' both ') - grid settings
plt.savefig () - save image
sub FIG. 1
Fig, AX = plt.subplots () - subgraph
ax.xaxis.set_major_locator (ticker.MultipleLocator (5)) - defining a sub master FIG abscissa scale
ax.xaxis.set_minor_locator (ticker.MultipleLocator (1)) - FIG. define the abscissa scale views
ax.xaxis.grid (True, which = 'minor ') - x-coordinate axis of the grid using the main scale network # grid coordinates using
ax.tick_params (which = 'minor', direction = 'in')
sub FIG. 2
AX1 plt.subplot2grid = ((2,. 1), (0, 0), rowspan =. 1, colspan =. 1)
AX2 of = plt.subplot2grid ((2, 1) , (1, 0), rowspan = 1,colspan=1)
plt.setp (ax1.get_xticklabels (), visible = False) # HIDE FIG upper sub x coordinate
plt.subplots_adjust (hspace = 0.1)

Third, other modules

1, collections.deque two-way queue, you can pop from the left, the right to join

Guess you like

Origin www.cnblogs.com/GavinSimons/p/11069917.html