python pandas Get the operation method of csv specified column and column

  • 2021-07-16 02:38:48
  • OfStack

pandas Get csv Specify Row, Column

house_info = pd.read_csv('house_info.csv')

1: Row fetching operation:

house_info.loc[3:6] Slicing operation similar to python

2: Column fetching operation:

house_info['price']  This is the default line 1 index when reading csv files

3: Take two columns

house_info[['price',tradetypename']] It is the same to take multiple columns. Note that there is a list of list, otherwise an error will be reported;

4: Add columns:

house_Info['adress_new']=list([.....])  It is somewhat similar to the operation of dictionary;

5: Divide a column by its maximum value, so that you can get a numerical range of 0 and 1, that is, a simple normalization operation;


house_info['price']/house_info['price'].max()

6: Sort columns:

house_info.sorted_values('price',inplace=True,ascending=True) The inplace here indicates whether a new dataframe structure is generated when reordering. ascending=true Indicates ascending order, which is also ascending by default; One more thing to note is that for the default value, (Nan) will rank it at the end when sorting;

7: How to get the default value,:


column_null = pd.isnull(column)
column_is_null_true = column[column_null]

Summarize


Related articles: