1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| def demo_create_dataframe_1(): data = [['tom', 10], ['nick', 15], ['juli', 14]] df = pd.DataFrame(data, columns = ['Name', 'Age']) print(df)
def demo_create_dataframe_2(): data = {'Name':['Tom', 'nick', 'krish', 'jack'], 'Age':[20, 21, 19, 18]} df = pd.DataFrame(data) print(df)
def demo_append_dataframe(): df1 = df = pd.DataFrame({"a":[1, 2, 3, 4], "b":[5, 6, 7, 8]}) df2 = pd.DataFrame({"a":[1, 2, 3], "b":[5, 6, 7]}) print(df1, "\n") new_df = df1.append(df2, ignore_index = True) print(new_df)
def demo_pandas_index(): data = {'Name':['Tom', 'nick', 'krish', 'jack'], 'Age':[20, 21, 19, 18]} df = pd.DataFrame(data) df.to_csv('data.csv',index=False) df = pd.read_csv('file_name.csv') df.to_csv('data.csv ', index=True) df_new = pd.read_csv('data.csv').drop(['unnamed 0'],axis=1)
|