Python Pandas
This is a page with all the information I’ve compiled on using the pandas
module within python.
Creating DataFrames
Starting with list of columns and column names
columns = [x1, x2, x3]
column_names = ['a', 'b', 'c']
df = pd.DataFrame(columns, index=column_names).T # Method 1
df = pd.DataFrame(list(zip(*columns)), columns=columns) # Method 2
Appending to DF
df.loc[len(df)] = [x1, x2, x3] # Method 1
df = pd.concat([df, pd.DataFrame([{'col1': x1, 'col2': x2, 'col3': x3}])]) # Method 2
Saving DFs
df.to_csv(filename, index=False)
Filtering DataFrames
df.loc[df['col1]=='val1']
Find and Replace
Written on October 26, 2023