2015-01-29 5 views
2

나는 다음과 같은 팬더 dataframe 한이 플롯하는 방법andrew_curves를 사용하여 pandas 데이터 프레임을 플로팅하는 방법은 무엇입니까?

andrews_curves(df, 'Name') 

어떤 생각? :

df = pd.read_csv('path/file/file.csv', 
       header=0, sep=',', names=['PhraseId', 'SentenceId', 'Phrase', 'Sentiment']) 

내가 andrew_curves로 인쇄하고 싶은 나는 다음과 같은 시도 당신이 연결

PhraseId, SentenceId, Phrase, Sentiment 
1, 1, A series of escapades demonstrating the adage that what is good for the goose is also good for the gander , some of which occasionally amuses but none of which amounts to much of a story ., 1 
2, 1, A series of escapades demonstrating the adage that what is good for the goose, 2 
3, 1, A series, 2 
4, 1, A, 2 
5, 1, series, 2 
6, 1, of escapades demonstrating the adage that what is good for the goose, 2 
7, 1, of, 2 
8, 1, escapades demonstrating the adage that what is good for the goose, 2 
9, 1, escapades, 2 
10, 1, demonstrating the adage that what is good for the goose, 2 
11, 1, demonstrating the adage, 2 
12, 1, demonstrating, 2 
13, 1, the adage, 2 
14, 1, the, 2 
15, 1, adage, 2 
16, 1, that what is good for the goose, 2 
17, 1, that, 2 
18, 1, what is good for the goose, 2 
19, 1, what, 2 
20, 1, is good for the goose, 2 
21, 1, is, 2 
22, 1, good for the goose, 3 
23, 1, good, 3 
24, 1, for the goose, 2 
25, 1, for, 2 
26, 1, the goose, 2 
27, 1, goose, 2 
28, 1, is also good for the gander , some of which occasionally amuses but none of which amounts to much of a story ., 2 
29, 1, is also good for the gander , some of which occasionally amuses but none of which amounts to much of a story, 2 
+0

를 얻을? 오류가 있었습니까? – cpburnz

답변

2

the doc page에서가, 조리개 데이터 세트가 'Name'라는 열이 :이 CSV의 내용이다. 당신이

andrews_curves(data, 'Name') 

를 호출 할 때 data의 행은 Name의 값으로 그룹화됩니다. 그래서 Iris 데이터 세트의 경우 세 가지 다른 색상을 얻을 수 있습니다.

데이터 세트에는 A, B, C의 세 열이 있습니다. df에서 andrews_curves으로 전화하려면 먼저 그룹화 할 값을 식별해야합니다. 예를 들어, 그것은 C 열의 값이면 다른 한편으로는, 당신은 열 이름, A, B, C에 의해 그룹 하려는 경우, 먼저, 을

andrews_curves(data, 'C') 

전화 긴 형식으로 다양한 형식에서 변환하기 위해 DataFrame 용융 및 는 (각 행에 대한 값 A, B, 또는 C을 보유하고 있음) variableandrews_curves 전화 :

,369을
import numpy as np 
import pandas as pd 
import pandas.tools.plotting as pdplt 
import matplotlib.pyplot as plt 

x = np.linspace(-1, 1, 1000) 
df = pd.DataFrame({'A': np.sin(x**2)/x, 
        'B': np.sin(x)*np.exp(-x), 
        'C': np.cos(x)*x}) 
pdplt.andrews_curves(pd.melt(df), 'variable') 
plt.show() 

당신이 시도 무엇을 잘못 무엇

enter image description here

+0

이것은 너무 추상적입니다. 나는 "열쇠를 바꾸는 것"이 ​​무엇을 의미하는지 모른다. 'text.csv' 샘플과 실행중인 코드를 게시하여 TypeError를 발생 시키십시오. – unutbu

+0

도와 주셔서 감사합니다. @unutbu. 나는 질문을 업데이트했고, 작은 intance 데이터가 주어지면 andrews 곡선을 그릴 계획이다. – skwoi

+0

@skwoi : 'andrews_curves' 함수는 데이터 프레임의 모든 열이 숫자가 될 것으로 예상합니다. 'Phrase' 컬럼을 어떤 종류의 숫자로 변환하고 싶을 것입니다. 어떻게 나에게 그렇게 할 것인지 분명하지 않습니다. 다른 문제는 그룹화 할 열을 지정해야한다는 것입니다. 귀하의 데이터에는 확실한 후보자가 없습니다. – unutbu

관련 문제