pandas-dataclasses
pandas-dataclasses copied to clipboard
[Feature request] Read CSV
I thought it could be a nice thing to have a read_csv class method in a pandas_dataclass. For example, suppose I have a CSV like the one below and I'd like to load it into a Weather dataclass defined at the beginning of the README. I could just call a Weather.read_csv(path) and it would cast values, name columns and indexes automatically.
| id | year | month | temp | wind | pressure |
|---|---|---|---|---|---|
| 1 | 2020 | 1 | 7.1 | 2.4 | 101 |
| 2 | 2020 | 7 | 24.3 | 3.1 | 103 |
| 3 | 2021 | 1 | 5.4 | 2.3 | 102 |
| 4 | 2021 | 7 | 25.9 | 2.4 | 100 |
df_weather = Weather.read_csv("weather_data.csv")
> df_weather
temp wind
year month
2020 1 7.1 2.4
7 24.3 3.1
2021 1 5.4 2.3
7 25.9 2.4
@adri0 Thank you for the idea! Let me think a while about how I can implement the proposed function.
Really like the idea of your package and will experiment - also agree with the proposed feature although probably worth supporting all read/write methods - not sure if there is an easy way to “wrap” the underlying Pandas methods? Also wondering about version 2.x of Pandas support?
Keep up the great work!