'How to convert a list from Google Sheets into Python?
I am trying to convert a list of items from Google Sheets, into a list for python.
For example, this is how it looks right now;
A
B
C
D
When I want it to look like this in Python;
['A', 'B', 'C', 'D'}
Is that possible at all, to copy a list of items from Google Sheets into Python? Manually typing everything out is a real pain, so I would love to know whether or not this could be done.
Best wishes,
Bruhammydude
Solution 1:[1]
Export your Google Sheets as a CSV file
use Pandas to read CSV file
Select and export column as a list
df = pandas.read_csv("csv_file_name") item_list = df["column_name"].tolist()
Solution 2:[2]
There is a way to import the data directly from google sheets, without export to csv, you do it as you like more, writing half line of code.
I was looking fast importing data, and get out of the IDE to do the csv export was f***ing me so i looked for a fast direct way.
Here is the way, tested. Ryan Jones tell you how to do it in a 2 min video. video
And this are the lines of code you need.
import pandas as pd
sheet_id = '1WxkdUPn9lUj6T2******7io7MMZvjd08LjYKk35Vf8w'
df = pd.read_csv(f'https://docs.google.com/spreadsheets/d/{sheet_id}/export?format=csv')
print(df.columnhead)
Where columhead is the name you gave to your column data (see the picture)
The magic line is
/export?format=csv
Nice
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Harsha Biyani |
| Solution 2 |
