Common commands for python, pandas and numpy

Python commonly used commands:

1. Divisibility: //

print(3//2)
>>>
1

Common commands under Pandas:

1. Read table data: pd.read_csv(path=' ', header=None): Read a .csv file without header;

                            pd.read_csv(path=' '): By default, the .csv file containing the table header is read;

There is too much table data, read in batches:

chunksize = 10000
whole_features = pd.read_csv(path, iterator=True)
for i in range(2941):
    whole_features = whole_features.get_chunk(size=chunksize)

2. Check the data types in pd: pd.dtypes; (np: np.dtype);

3.df locates the last column: df.iloc[:, -1];

4. Splicing: pd.concat([pd1,pd2],axis=0): Splicing by row;

              pd.concat([pd1,pd2],axis=1): concatenate by columns;

5. Convert pd to numpy format (pd->>>numpy): pd1.to_numpy();

6. Convert numpy to pd format (numpy->>pd): pd.DataFrame(numpy1)

7. Known to list, read a certain column: data=df[feature_name]

8. Generate an empty DataFrame: df=pd.DataFrame([])

Numpy common commands

1. Create an empty array: a=[]; a.append(v)

2. Return the subscript corresponding to the maximum value: np.argmax(numpy1, axis=1): find the maximum value by column;

3. Convert tensor tensor to numpy: np.array(tensor1)

4. Convert numpy to tensor:  

5. The statistical characteristics of numpy: np.mean(numpy1, axis=0): find the mean by row;

                                   np.std() or numpy1.std();

                                   numpy1.max(): Find the maximum value:

6. Numpy changes the data type: numpy1.astype(np.uint8): changes the original data type to numpy integer type;

7. Set random seed: np.random.seed(256);

8. Generate the specified element of the specified shape: np.full(shape, full_value)

                            

Guess you like

Origin blog.csdn.net/weiyuangong/article/details/125603127