dplython not working.. why?

89 views
Skip to first unread message

THIAM HUAT Tan

unread,
Apr 3, 2018, 3:46:47 AM4/3/18
to dplython
from dplython import *
from dplython import X as X_dpl
from dplython import (DplyFrame, X, diamonds, select, sift,
  sample_n, sample_frac, head, arrange, mutate, group_by,
  summarize, DelayFunction)

df = DplyFrame(pd.read_csv('test.csv'))
print(type(df))
print(df)

<class 'dplython.dplython.DplyFrame'> service_point_sn;meter_sn;MinCons_60;date;OpenClose 0 3004478638;WS500001A;3;2016-06-08;Open 1 3004478638;WS500001A;0;2016-10-06;Close 2 3004478638;WS500001A;8;2017-10-30;Open 3 3004478638;WS500001A;0;2017-11-26;Close 4 3004478658;WS500007A;18;2017-01-18;Open 5 3004478658;WS500007A;0;2017-01-22;Close 6 3004478658;WS500007A;3;2017-08-17;Open 7 3004478658;WS500007A;0;2017-12-24;Close 8 3004478658;WS500007A;6;2018-01-23;Open 9 3004478742;WS500031A;2;2016-03-27;Open 10 3004478742;WS500031A;0;2016-10-09;Close 11 3004478742;WS500031A;2;2016-10-14;Open 12 3004478742;WS500031A;0;2016-11-01;Close

df >> select(X.service_point_sn, X.OpenClose)

--------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-90-3e11691cf018> in <module>() ----> 1 df >> select(X.service_point_sn, X.OpenClose) /usr/local/lib/python3.6/dist-packages/dplython/dplython.py in __rshift__(self, delayedFcn) 114 else: 115 otherDf = DplyFrame(self.copy(deep=True)) --> 116 return delayedFcn(otherDf) 117 118 /usr/local/lib/python3.6/dist-packages/dplython/dplython.py in <lambda>(df) 228 columns.insert(0, col) 229 return columns --> 230 return lambda df: df[select_columns(df, args)] 231 232 /usr/local/lib/python3.6/dist-packages/pandas/core/frame.py in __getitem__(self, key) 2131 if isinstance(key, (Series, np.ndarray, Index, list)): 2132 # either boolean or fancy integer index -> 2133 return self._getitem_array(key) 2134 elif isinstance(key, DataFrame): 2135 return self._getitem_frame(key) /usr/local/lib/python3.6/dist-packages/pandas/core/frame.py in _getitem_array(self, key) 2175 return self._take(indexer, axis=0, convert=False) 2176 else: -> 2177 indexer = self.loc._convert_to_indexer(key, axis=1) 2178 return self._take(indexer, axis=1, convert=True) 2179 /usr/local/lib/python3.6/dist-packages/pandas/core/indexing.py in _convert_to_indexer(self, obj, axis, is_setter) 1267 if mask.any(): 1268 raise KeyError('{mask} not in index' -> 1269 .format(mask=objarr[mask])) 1270 1271 return _values_from_object(indexer) KeyError: "['service_point_sn' 'OpenClose'] not in index"

Christopher Riederer

unread,
Apr 3, 2018, 12:04:22 PM4/3/18
to THIAM HUAT Tan, dplython
Hi there,
It looks to me that your data is semicolon delimited and not comma delimited. When you're using pd.read_csv, it's reading your data frame as having one column as a string. Try looking at df.columns to see what I mean, I suspect it will be just one column. Try replacing semicolons with commas in your file, or using delimter=';' as a keyword arg in pd.read_csv

Thank you for using dplython!
Chris

--
You received this message because you are subscribed to the Google Groups "dplython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dplython+u...@googlegroups.com.
To post to this group, send email to dply...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dplython/006c1ed3-9e41-479a-b5f2-9047f41c8608%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

THIAM HUAT Tan

unread,
Apr 4, 2018, 5:47:45 AM4/4/18
to Christopher Riederer, dplython
Hi Chris,

thanks for your kind reply. I have been solving this for days and weeks, and finally you give me the exact answer.
Thank you. Your package dplython is very useful, as I come from R background, and want to do more with Python, 
and your package is especially useful for data manipulation, like dplyr in R.

Cheers,
Thiam Huat

Chris


To unsubscribe from this group and stop receiving emails from it, send an email to dplython+unsubscribe@googlegroups.com.

To post to this group, send email to dply...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dplython/006c1ed3-9e41-479a-b5f2-9047f41c8608%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "dplython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dplython+unsubscribe@googlegroups.com.

To post to this group, send email to dply...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages