Programming Part 5 Flashcards
(20 cards)
How do you read a CSV file in pandas?
pd.read_csv(‘filename.csv’)
How do you write a DataFrame to a CSV file?
df.to_csv(‘filename.csv’, index=False)
How do you read a JSON file with pandas?
pd.read_json(‘filename.json’)
How do you read an Excel file with pandas?
pd.read_excel(‘filename.xlsx’)
How do you write a DataFrame to an Excel file?
df.to_excel(‘filename.xlsx’, index=False)
How do you open a file in Python?
with open(‘file.txt’, ‘r’) as f:
What does ‘r’ mode mean in open()?
Read-only mode.
What does ‘w’ mode mean in open()?
Write mode; overwrites the file.
How do you read all lines from a file?
f.readlines()
How do you write to a file?
f.write(‘some text’)
What is an API?
An Application Programming Interface that allows software to communicate with other systems.
What is a REST API?
A type of web API based on representational state transfer principles.
How do you make a GET request in Python?
Using requests.get(‘url’)
How do you pass query parameters in a GET request?
requests.get(‘url’, params={‘key’: ‘value’})
How do you read a JSON response from an API?
response.json()
How do you convert a string to lowercase?
string.lower()
How do you split a string by spaces?
string.split()
How do you join a list of strings?
’ ‘.join(list_of_strings)
How do you replace part of a string?
string.replace(‘old’, ‘new’)
How do you strip whitespace from a string?
string.strip()