CodeX
Published in

CodeX

Can Pandas take on SQL?

Who will win?

Importing data

SQL

CREATE TABLE dataset_name (
column1 character data_type(30),
column2 character data_type(50),
column3 data_type,
);copy fert_data from ‘Path\to\file’ with delimiter ‘,’ csv header encoding ‘windows-1251’;

Pandas

df = pd.read_csv(’Path\to\your\dataset’)

Select

SQL

SELECT column_name1, column_name2,…
FROM table_name;
df[[‘column_name1’, ‘column_name2’]]

Where

SQL

SELECT *
FROM table_name
WHERE condition_expression;

Pandas

df[df[‘column_name’] == value] # for Boolean indexingdf[df.loc[‘column_name’] == value] # for positional indexing

Insert

SQL

INSERT INTO table_name(column_name_1, column_name_2,…) VALUES (value1, value2,…);

Pandas

df = df.append(new_row_to_be_inserted, ignore_index=True)

Update

SQL

UPDATE table_name
SET column_name = ‘modified_value’
WHERE condition;

Pandas

Conclusion

--

--

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store