1import pandas as pd
2
3data = {'name': ['Somu', 'Kiku', 'Amol', 'Lini'],
4 'physics': [68, 74, 77, 78],
5 'chemistry': [84, 56, 73, 69],
6 'algebra': [78, 88, 82, 87]}
7
8
9#create dataframe
10df_marks = pd.DataFrame(data)
11print('Original DataFrame\n------------------')
12print(df_marks)
13
14new_row = {'name':'Geo', 'physics':87, 'chemistry':92, 'algebra':97}
15#append row to the dataframe
16df_marks = df_marks.append(new_row, ignore_index=True)
17
18print('\n\nNew row added to DataFrame\n--------------------------')
19print(df_marks)
1# Add a new row at index k with values provided in list
2dfObj.loc['k'] = ['Smriti', 26, 'Bangalore', 'India']
3
1 df.loc[-1] = [2, 3, 4] # adding a row
2 df.index = df.index + 1 # shifting index
3 df = df.sort_index() # sorting by index