<jupyter_start><jupyter_text>Appending to DataFrame<jupyter_code>import pandas as pd
 
df = pd.DataFrame(columns = ['A','B','C'])
df<jupyter_output><empty_output><jupyter_text>df.loc --> https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.loc.htmlto access data by using row/values we use df.loc<jupyter_code>df.loc[0,'A'] = 1
df
df.loc[1] = [2,3,4]
df
df.loc[2] = {'A':3, 'C':9, 'B':9}
df<jupyter_output><empty_output><jupyter_text>The first input in .loc[] is the index. If you use an existing index, you will overwrite the values in thatrow:<jupyter_code>df.loc[1] = [5, 6, 7]
df
df.loc[0, 'B'] = 8
df<jupyter_output><empty_output><jupyter_text>Adding a dataframe to another<jupyter_code>df1 = pd.DataFrame([['a1','b1'],['a2','b2']],columns=['A','B'])
df1
df2 = pd.DataFrame([['b1','c1'],['b2','c2']],columns=['B','C'])
df2<jupyter_output><empty_output><jupyter_text>The two DataFrames are not required to have the same set of columns. The append method doesnot change either of the original DataFrames. Instead, it returns a new DataFrame by appendingthe original two. Appending a DataFrame to another one is quite simple:<jupyter_code>df1.append(df2)<jupyter_output><empty_output><jupyter_text>As you can see, it is possible to have duplicate indices (0 in this example). To avoid this issue, youmay ask Pandas to reindex the new DataFrame for you:<jupyter_code>df1.append(df2,ignore_index=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14930555555555555, 'fraction_numerical': 0.022916666666666665, 'mean_word_length': 7.050279329608938, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 26, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '81824', 'license': 'MIT', 'n_tokens_mistral': 553, 'n_tokens_neox': 540, 'n_words': 135, 'path': '3.adding to dataframe.ipynb', 'repo_name': 'yadav-vikas/Pandas-tutorial-for-beginners', 'size': '1440'}