12.3.10.4.4. Getting data in/out
import pandas as pd
import numpy as np
timestamps = pd.Series(
np.random.randn(1000), index=pd.date_range("1/1/2000", periods=1000)
)
timestamps = timestamps.cumsum()
dataFrame = pd.DataFrame(
np.random.randn(1000, 4), index=timestamps.index, columns=["A", "B", "C", "D"]
)
dataFrame = dataFrame.cumsum()
dataFrame.to_csv("foo.csv")
pd.read_csv("foo.csv")
|
Unnamed: 0 |
A |
B |
C |
D |
0 |
2000-01-01 |
-0.791861 |
-0.558487 |
0.260862 |
-0.827079 |
1 |
2000-01-02 |
-0.728893 |
0.018522 |
0.491820 |
0.427598 |
2 |
2000-01-03 |
0.801129 |
-0.788797 |
0.187535 |
0.424554 |
3 |
2000-01-04 |
0.003962 |
-1.998664 |
-0.078471 |
1.017862 |
4 |
2000-01-05 |
0.529178 |
-1.765030 |
-0.781073 |
1.237441 |
... |
... |
... |
... |
... |
... |
995 |
2002-09-22 |
22.183364 |
-29.935107 |
-32.450743 |
19.144473 |
996 |
2002-09-23 |
21.568148 |
-30.342366 |
-32.678239 |
19.158621 |
997 |
2002-09-24 |
22.086591 |
-28.859693 |
-32.059223 |
18.354344 |
998 |
2002-09-25 |
22.520814 |
-29.239886 |
-30.950673 |
18.254176 |
999 |
2002-09-26 |
24.098983 |
-29.360780 |
-29.249539 |
18.458504 |
1000 rows × 5 columns
dataFrame.to_excel("foo.xlsx", sheet_name="Sheet1")
pd.read_excel("foo.xlsx", "Sheet1", index_col=None, na_values=["NA"])
|
Unnamed: 0 |
A |
B |
C |
D |
0 |
2000-01-01 |
-0.791861 |
-0.558487 |
0.260862 |
-0.827079 |
1 |
2000-01-02 |
-0.728893 |
0.018522 |
0.491820 |
0.427598 |
2 |
2000-01-03 |
0.801129 |
-0.788797 |
0.187535 |
0.424554 |
3 |
2000-01-04 |
0.003962 |
-1.998664 |
-0.078471 |
1.017862 |
4 |
2000-01-05 |
0.529178 |
-1.765030 |
-0.781073 |
1.237441 |
... |
... |
... |
... |
... |
... |
995 |
2002-09-22 |
22.183364 |
-29.935107 |
-32.450743 |
19.144473 |
996 |
2002-09-23 |
21.568148 |
-30.342366 |
-32.678239 |
19.158621 |
997 |
2002-09-24 |
22.086591 |
-28.859693 |
-32.059223 |
18.354344 |
998 |
2002-09-25 |
22.520814 |
-29.239886 |
-30.950673 |
18.254176 |
999 |
2002-09-26 |
24.098983 |
-29.360780 |
-29.249539 |
18.458504 |
1000 rows × 5 columns
Total running time of the script: (0 minutes 1.071 seconds)