1df = pd.DataFrame({
2 'a':[1,2,3],
3 'b':[5,6,7]
4})
5
6df2 = pd.DataFrame({
7 'a':[11,12,13],
8 'b':[15,16,17]
9})
10
11df = df.append(df2, ignore_index = True )
12
13print(df)
1# append row to dataframe without index
2
3a_row = pd.Series([1, 2])
4df = pd.DataFrame([[3, 4], [5, 6]])
5
6row_df = pd.DataFrame([a_row])
7df = pd.concat([row_df, df], ignore_index=True)
8
9print(df)
10# OUTPUT
11# 0 1
12# 0 1 2
13# 1 3 4
14# 2 5 6
15
16# append row to dataframe with index
17
18a_row = pd.Series([1, 2])
19df = pd.DataFrame([[3, 4], [5, 6]], index = ["row1", "row2"])
20
21row_df = pd.DataFrame([a_row], index = ["row3"])
22df = pd.concat([row_df, df])
23
24print(df)
25# OUTPUT
26# 0 1
27# row3 1 2
28# row1 3 4
29# row2 5 6
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