pandas-dataclasses icon indicating copy to clipboard operation
pandas-dataclasses copied to clipboard

[Feature request] Read CSV

Open adri0 opened this issue 3 years ago • 2 comments

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 avatar Nov 05 '22 16:11 adri0

@adri0 Thank you for the idea! Let me think a while about how I can implement the proposed function.

astropenguin avatar Nov 08 '22 05:11 astropenguin

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!

Mjboothaus avatar May 05 '23 21:05 Mjboothaus