Project github address: bitcarmanlee easy-algorithm-interview-and-practice
often have students private messages or leave messages to ask related questions, V number bitcarmanlee. The classmates of star on github, within the scope of my ability and time, I will try my best to help you answer related questions and make progress together.
1. Test data
1457822940 0 0 44 36
422692440 0 0 3 3
1460826600 0 0 7 6
1410115140 -1 3 25 7
1161370800 0 0 18 14
996746700 0 0 30 25
1115896320 0 0 441 123
64954980 0 0 7 7
2307334696 0 0 2 2
417770700 0 0 1 1
2. Get the number of rows, columns, elements, etc.
def test():
names = ['c1', 'c2', 'c3', 'c4', 'c5']
df = pd.read_csv("testdata", sep="\t", header=None, names=names)
print(df.info())
print("\n")
print("len is: ", len(df))
print("columns is: ", df.columns)
print("shape is: ", df.shape)
print("size is: ", df.size)
Code output result:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 10 entries, 0 to 9
Data columns (total 5 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 c1 10 non-null int64
1 c2 10 non-null int64
2 c3 10 non-null int64
3 c4 10 non-null int64
4 c5 10 non-null int64
dtypes: int64(5)
memory usage: 528.0 bytes
None
len is: 10
columns is: Index(['c1', 'c2', 'c3', 'c4', 'c5'], dtype='object')
shape is: (10, 5)
size is: 50
Among them, the info() method contains a lot of information, including type, column information, number of non-null, data type, memory usage, etc.
len(df) can get the number of rows of the dataframe
column can get the information related to the column
shape is a two-tuple, including row and column information, so if you want to get the row and column data of the dataframe, you can get it through shape.
size is the number of elements in the entire dataframe.